xref: /php-src/tests/lang/030.phpt (revision 902d6439)
1--TEST--
2$this in constructor test
3--FILE--
4<?php
5class foo {
6    public $Name;
7    function __construct($name) {
8        $GLOBALS['List']= &$this;
9        $this->Name = $name;
10        $GLOBALS['List']->echoName();
11    }
12
13    function echoName() {
14        $GLOBALS['names'][]=$this->Name;
15    }
16}
17
18function &foo2(&$foo) {
19    return $foo;
20}
21
22
23$bar1 =new foo('constructor');
24$bar1->Name = 'outside';
25$bar1->echoName();
26$List->echoName();
27
28$foo = new foo('constructor');
29$bar1 =& foo2($foo);
30$bar1->Name = 'outside';
31$bar1->echoName();
32
33$List->echoName();
34
35print ($names==array('constructor','outside','outside','constructor','outside','outside')) ? 'success':'failure';
36?>
37--EXPECT--
38success
39