xref: /PHP-8.0/Zend/tests/bug44660.phpt (revision d30cd7d7)
1--TEST--
2Bug #44660 (Indexed and reference assignment to property of non-object don't trigger warning)
3--FILE--
4<?php
5$s = "hello";
6$a = true;
7
8echo "--> read access:";
9echo $a->p;
10
11echo "\n--> direct assignment:\n";
12try {
13    $a->p = $s;
14} catch (Error $e) {
15    echo $e->getMessage(), "\n";
16}
17
18echo "\n--> increment:\n";
19try {
20    $a->p++;
21} catch (Error $e) {
22    echo $e->getMessage(), "\n";
23}
24
25echo "\n--> reference assignment:\n";
26try {
27    $a->p =& $s;
28} catch (Error $e) {
29    echo $e->getMessage(), "\n";
30}
31
32echo "\n--> reference assignment:\n";
33try {
34    $s =& $a->p;
35} catch (Error $e) {
36    echo $e->getMessage(), "\n";
37}
38
39echo "\n--> indexed assignment:\n";
40try {
41    $a->p[0] = $s;
42} catch (Error $e) {
43    echo $e->getMessage(), "\n";
44}
45
46echo "\n--> Confirm assignments have had no impact:\n";
47var_dump($a);
48?>
49--EXPECTF--
50--> read access:
51Warning: Attempt to read property "p" on bool in %s on line %d
52
53--> direct assignment:
54Attempt to assign property "p" on bool
55
56--> increment:
57Attempt to increment/decrement property "p" on bool
58
59--> reference assignment:
60Attempt to modify property "p" on bool
61
62--> reference assignment:
63Attempt to modify property "p" on bool
64
65--> indexed assignment:
66Attempt to modify property "p" on bool
67
68--> Confirm assignments have had no impact:
69bool(true)
70