You can invoke a class above its definitions in some cases, but there are very important exceptions to this behavior. If your class extends another class, and the interpreter doesn't see the extended class first, then it won't be added to the symbol table until the code has stepped through it in runtime. As a result, if you try to invoke it above the definition, you'll get a "class not found" fatal error.
And those suck.
So, to provide an example, the following will output a fatal error
<?php
Bar::bar();
exit;
class Bar extends Foo { } class Foo {
static function bar() { echo 'yep, this is Foo::bar'; }
}
?>
However, THIS code will work just fine:
<?php
Bar::bar();
exit;
class Foo {
static function bar() { echo 'yep, this is Foo::bar'; }
}
class Bar extends Foo { } ?>
Notice that if you include a file containing the class you will extend, and then extend the class in the same file as its invocation, you can also get the class not found fatal. This happens even if the 'include' call happens before the child class's definition.
Eg. the following will also output a fatal error
<?php
include_once('file_with_foo.php');
Bar::bar();
exit;
class Bar extends Foo { }
?>
Hope that clarifies things.