030.phpt 673 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. $this in constructor test
  3. --FILE--
  4. <?php
  5. class foo {
  6. function __construct($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. $foo = new foo('constructor');
  23. $bar1 =& foo2($foo);
  24. $bar1->Name = 'outside';
  25. $bar1->echoName();
  26. $List->echoName();
  27. print ($names==array('constructor','outside','outside','constructor','outside','outside')) ? 'success':'failure';
  28. ?>
  29. --EXPECT--
  30. success