Method Or Property?¶
<?php
$object = new X();
$one = $object->foo(); // X::foo
$two = new $object->foo(); // object Y {}
class X {
public $foo = Y::class;
function foo() {
return __METHOD__;
}
}
class Y {}
?>
The first line is a simple call to the method foo, on an object whose class is not show here: if this works, there is a method foo() in that class.
The second line is a simple call to the property foo, on an object whose class is not know (again): it has a property called foo. Then, the result of that property, hopefully a string with a class name, or another object, is instantiated, without any arguments.
The nuance is subtle.
See Also¶
method or property? [Try me]
PHP Features¶
Last updated: 14 July 2026