fork(1) download
  1. <?php
  2.  
  3. class Test {
  4. public function foo() {
  5. function bar() {
  6. echo "Hello from bar!" . PHP_EOL;
  7. }
  8.  
  9. echo "Hello from foo!" . PHP_EOL;
  10. }
  11. }
  12.  
  13. $t = new Test;
  14. // PHP Fatal error: Call to undefined method Test::bar()
  15. // $t->bar();
  16.  
  17. // Works, prints "Hello from foo!"
  18. // bar() is now defined, but not where you expect
  19. $t->foo();
  20.  
  21. // PHP Fatal error: Call to undefined method Test::bar()
  22. // $t->bar();
  23.  
  24. // Works, prints "Hello from bar!"
  25. // Note that this is global scope, not from Test
  26. bar();
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Hello from foo!
Hello from bar!