xref: /PHP-7.3/tests/lang/030.phpt (revision 6bb81d2c)
1--TEST--
2$this in constructor test
3--FILE--
4<?php
5class foo {
6	function __construct($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$foo = new foo('constructor');
28$bar1 =& foo2($foo);
29$bar1->Name = 'outside';
30$bar1->echoName();
31
32$List->echoName();
33
34print ($names==array('constructor','outside','outside','constructor','outside','outside')) ? 'success':'failure';
35?>
36--EXPECT--
37success
38