Reputation: 529
I've noticed in PHP I can create a function without the static modifier but still call it as if it was a static function, just curious why this is allowed / what is actually happening.
class Foo {
public function bar($i) {
return $i + 1;
}
}
Foo::bar(4); // 5
I would expect that the static modifier is required like:
class Foo {
public static function bar($i) {
return $i + 1;
}
}
Foo::bar(4); // 5
Upvotes: 2
Views: 72
Reputation: 10420
It's for compatibility with PHP4 where the described behavior was how it actually worked (there was no static
keyword).
You should be getting an E_STRICT
error, though, unless your error_reporting
is set to not display E_STRICT
.
Upvotes: 5