Reputation: 1969
<?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?
Upvotes: 0
Views: 33
Reputation: 4091
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
Upvotes: 1