What's the difference between $foo->bar() and $foo::bar()?
$foo::bar() is a call of the static method bar(), that means the object $foo was not instanciated by the __construct() method.
When calling $foo->bar(), the object $foo has to be instanciated before! Example:
$foo = new Foo; // internally the method __constuct() is called in the Foo class!
echo $foo->bar();
Often you don't call a static method on a existing object like in you example ($foo), you can call it directly on the class Foo:
Foo::bar();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With