xref: /PHP-5.6/tests/classes/this.phpt (revision 610c7fbe)
1--TEST--
2ZE2 $this cannot be exchanged
3--SKIPIF--
4<?php if (version_compare(zend_version(), '2.0.0-dev', '<')) die('skip ZendEngine 2 needed'); ?>
5--FILE--
6<?php
7
8/* please don't shorten this test. It shows what would happen if
9 * the fatal error would have been a warning.
10 */
11class Foo
12{
13    function replace($other)
14    {
15    	echo __METHOD__ . "\n";
16        $this = $other;
17        print $this->prop;
18        print $other->prop;
19    }
20
21    function indirect($other)
22    {
23    	echo __METHOD__ . "\n";
24        $this = $other;
25        $result = $this = $other;
26        print $result->prop;
27        print $this->prop;
28    }
29
30    function retrieve(&$other)
31    {
32    	echo __METHOD__ . "\n";
33    	$other = $this;
34    }
35}
36
37$object = new Foo;
38$object->prop = "Hello\n";
39
40$other  = new Foo;
41$other->prop = "World\n";
42
43$object->replace($other);
44$object->indirect($other);
45
46print $object->prop; // still shows 'Hello'
47
48$object->retrieve($other);
49print $other->prop;  // shows 'Hello'
50
51?>
52===DONE===
53--EXPECTF--
54Fatal error: Cannot re-assign $this in %sthis.php on line %d
55