Reputation: 45320
How is this working? Shouldn't this throw an error, since I am trying to call a non static method statically? Basically, I've never instantiated an object of type something.
class Something {
public function helloworld() {
echo 'hello world';
}
}
Something::helloworld();
Upvotes: 1
Views: 163
Reputation: 22783
Put this at the top of your script:
error_reporting( E_ALL | E_STRICT ); // E_STRICT is important here
ini_set( 'display_errors', true );
... and see what happens then:
Strict Standards: Non-static method Something::helloworld() should not be called statically in [...]
Admittedly, it more of a notice than an error though. Your script will happily continue to run.
Upvotes: 1
Reputation: 34612
It would only give you an error, if within helloworld()
you'd be using $this
.
It's a type of PHP "WTF" resulting from missing specs that allows you to statically invoke a function not actually declared static
.
Upvotes: 0