0
<?php class Main { public function findSub($name = null) { Sub::show($name); } } class Sub { public function show($name = null) { echo 'I am ' . $name; } } $main = new Main; $main->findSub('chan'); // I am chan 

As I remembered, if you want to use another class by className::functionName(), you need to declare the function as static, in this case I call show in static way without declare the function as static function, but it still work, how come?

1 Answer 1

1

So far I think you have E_STRICT warnings suppressed. It works (likely for legacy reasons), but it's not recommended.For legacy reasons, any class method could be called statically even if it wasn't declared static, because you previously couldn't declare them as such.

Calling non-static methods statically generates an E_STRICT level warning. 

For official documentation refer this

Sign up to request clarification or add additional context in comments.

1 Comment

Also in higher versions of php you might get fatal errors when you call non static php functions statically.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.