xref: /PHP-7.4/Zend/tests/bug36214.phpt (revision 1624b0a9)
1--TEST--
2Bug #36214 (__get method works properly only when conditional operator is used)
3--FILE--
4<?php
5class context {
6  public $stack = array();
7
8  public function __set($name,$var) {
9    $this->stack[$name] = $var;return;
10  }
11
12  public function &__get($name) {
13    return $this->stack[$name];
14  }
15}
16
17$ctx = new context;
18$ctx->comment_preview = array();
19$ctx->comment_preview[0] = 1;
20$ctx->comment_preview[1] = 2;
21var_dump($ctx->comment_preview);
22
23$comment_preview = array();
24$comment_preview[0] = 1;
25$comment_preview[1] = 2;
26$ctx->comment_preview = $comment_preview;
27var_dump($ctx->comment_preview);
28
29$ctx->comment_preview = new ArrayObject();
30$ctx->comment_preview[0] = 1;
31$ctx->comment_preview[1] = 2;
32var_dump($ctx->comment_preview);
33?>
34--EXPECTF--
35array(2) {
36  [0]=>
37  int(1)
38  [1]=>
39  int(2)
40}
41array(2) {
42  [0]=>
43  int(1)
44  [1]=>
45  int(2)
46}
47object(ArrayObject)#%d (1) {
48  ["storage":"ArrayObject":private]=>
49  array(2) {
50    [0]=>
51    int(1)
52    [1]=>
53    int(2)
54  }
55}
56