While the order of execution is correct, PHP actually does not execute the use statement, but interpret it statement-by-statement while generating bytecode for the function. It will select the wrong class for the bytecode and everything will go haywire.
For the sake of completeness, here is a test class which will show that the above code indeed does not run properly. Add an include line for it right after the <?php of each code snippet.
// BarClass.php
<?php
namespace FooNamespace;
class BarClass {
public static function foo() {
echo "foo";
}
}
Test case:
Example obfuscated output:
While the order of execution is correct, PHP actually does not execute the
use
statement, but interpret it statement-by-statement while generating bytecode for the function. It will select the wrong class for the bytecode and everything will go haywire.For the sake of completeness, here is a test class which will show that the above code indeed does not run properly. Add an include line for it right after the
<?php
of each code snippet.