030.phpt 625 B

123456789101112131415161718192021222324252627282930313233343536
  1. --TEST--
  2. $this in constructor test
  3. --FILE--
  4. <?php
  5. class foo {
  6. function foo($name) {
  7. $GLOBALS['List']= &$this;
  8. $this->Name = $name;
  9. $GLOBALS['List']->echoName();
  10. }
  11. function echoName() {
  12. $GLOBALS['names'][]=$this->Name;
  13. }
  14. }
  15. function &foo2(&$foo) {
  16. return $foo;
  17. }
  18. $bar1 =new foo('constructor');
  19. $bar1->Name = 'outside';
  20. $bar1->echoName();
  21. $List->echoName();
  22. $bar1 =& foo2(new foo('constructor'));
  23. $bar1->Name = 'outside';
  24. $bar1->echoName();
  25. $List->echoName();
  26. print ($names==array('constructor','outside','outside','constructor','outside','outside')) ? 'success':'failure';
  27. ?>
  28. --EXPECT--
  29. success