Well, I don't get why this code works
class MyObject {
public function myBaseMethod()
{
echo 'I\'m declared in' . __CLASS__;
}
}
$instance = new MyObject();
$instance->myBaseMethod();
MyObject::myBaseMethod();
// Output
I'm declared inMyObject
I'm declared inMyObject
I can invoke myBaseMethod() by creating new instance of a MyObject class or as static method. But myBaseMethod is not declared as static.
I thought that I can use :: only for static members/methods.
Any explanations pls
Yeah it is possible. I would like to know why. But note that PHP will throw an E_STRICT error which is definitely not acceptable for new code while it might happen in legacy code. You should not call methods static which were not declared as static. Try to fix legacy code.
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