0

I just recently discovered this strange behavior in my project.

I have a method that I accidentally defined as just a function (it's supposed to be public static), and then I called this method statically – and it still worked! Why is this?

class C {
   function n() {
      ...
   }
}

$y = C::n();  // This works, method is performed as intended, and without errors

By the way, I am using version 5.4.

silkfire
  • 24,585
  • 15
  • 82
  • 105
  • 2
    Have a look at this thread. http://stackoverflow.com/questions/3754786/calling-non-static-method-with And also you might even see a warning if you have strict reporting on – Sajuna Fernando Oct 22 '13 at 08:23
  • 1
    Any accessible method can be called in a static context, only a warning will be raised and obviously any reference to `$this` will cause an error. – AlexP Oct 22 '13 at 08:25
  • @AlexP I'm not getting any warnings at all =/ – silkfire Oct 22 '13 at 08:45

0 Answers0