xref: /PHP-8.2/Zend/tests/bug28444.phpt (revision f8d79582)
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--EXPECT--
56object(ObjectOne)#2 (1) {
57  ["x"]=>
58  int(2)
59}
60int(2)
61int(3)
62Overloaded::__set(y,3)
63int(3)
64Overloaded::__get(y)
65int(3)
66Overloaded::__set(z,Object)
67object(ObjectOne)#3 (1) {
68  ["x"]=>
69  int(4)
70}
71Overloaded::__get(z)
72int(4)
73Overloaded::__get(z)
74int(5)
75Overloaded::__get(z)
76int(6)
77