3

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

dofenco
  • 315
  • 1
  • 3
  • 11

1 Answers1

6

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.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266