xref: /PHP-7.4/Zend/tests/bug28444.phpt (revision a31f4642)
1--TEST--
2Bug #28444 (Cannot access undefined property for object with overloaded property access)
3--FILE--
4<?php
5
6class ObjectOne
7{
8	public $x;
9
10	function __construct($x)
11	{
12		$this->x = $x;
13	}
14
15	function __toString() {
16		return "Object";
17	}
18}
19
20class Overloaded
21{
22	public $props = array();
23	public $x;
24
25	function __construct($x)
26	{
27		$this->x = new ObjectOne($x);
28	}
29
30	function __get($prop)
31	{
32		echo __METHOD__ . "($prop)\n";
33		return $this->props[$prop];
34	}
35
36	function __set($prop, $val)
37	{
38		echo __METHOD__ . "($prop,$val)\n";
39		$this->props[$prop] = $val;
40	}
41}
42$y = new Overloaded(2);
43var_dump($y->x);
44var_dump($y->x->x);
45var_dump($y->x->x = 3);
46var_dump($y->y = 3);
47var_dump($y->y);
48var_dump($y->z = new ObjectOne(4));
49var_dump($y->z->x);
50$t = $y->z;
51var_dump($t->x = 5);
52var_dump($y->z->x = 6);
53
54?>
55===DONE===
56--EXPECT--
57object(ObjectOne)#2 (1) {
58  ["x"]=>
59  int(2)
60}
61int(2)
62int(3)
63Overloaded::__set(y,3)
64int(3)
65Overloaded::__get(y)
66int(3)
67Overloaded::__set(z,Object)
68object(ObjectOne)#3 (1) {
69  ["x"]=>
70  int(4)
71}
72Overloaded::__get(z)
73int(4)
74Overloaded::__get(z)
75int(5)
76Overloaded::__get(z)
77int(6)
78===DONE===
79