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