Skip to content

Commit 9d400d1

Browse files
committed
Improve error messages for invalid property access
1 parent 7183717 commit 9d400d1

31 files changed

+98
-95
lines changed

Zend/tests/024.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ NULL
4141
Warning: Undefined variable $b in %s on line %d
4242
int(1)
4343

44-
Warning: Trying to get property '1' of non-object in %s on line %d
44+
Warning: Attempt to read property '1' on int in %s on line %d
4545
NULL
4646

47-
Warning: Trying to get property '1' of non-object in %s on line %d
47+
Warning: Attempt to read property '1' on int in %s on line %d
4848
NULL
4949

5050
Warning: Undefined variable $c in %s on line %d
5151

5252
Warning: Trying to access array offset on value of type null in %s on line %d
5353

54-
Warning: Trying to get property '1' of non-object in %s on line %d
54+
Warning: Attempt to read property '1' on int in %s on line %d
5555

56-
Warning: Trying to get property '' of non-object in %s on line %d
56+
Warning: Attempt to read property '' on null in %s on line %d
5757
NULL

Zend/tests/026.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ print "ok\n";
2222

2323
?>
2424
--EXPECTF--
25-
Warning: Trying to get property 'a' of non-object in %s on line %d
25+
Warning: Attempt to read property 'a' on null in %s on line %d
2626
ok
27-
Attempt to assign property 'a' of non-object
27+
Attempt to assign property 'a' on null
2828
ok

Zend/tests/033.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ Warning: Trying to access array offset on value of type null in %s on line %d
6161

6262
Warning: Trying to access array offset on value of type null in %s on line %d
6363

64-
Warning: Trying to get property 'foo' of non-object in %s on line %d
65-
Attempt to assign property 'foo' of non-object
66-
Attempt to assign property 'bar' of non-object
64+
Warning: Attempt to read property 'foo' on null in %s on line %d
65+
Attempt to assign property 'foo' on null
66+
Attempt to assign property 'bar' on null

Zend/tests/assign_dim_obj_null_return.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ Cannot add element to the array as the next element is already occupied
7979
Illegal offset type
8080
Illegal offset type
8181
Cannot use a scalar value as an array
82-
Attempt to assign property 'foo' of non-object
83-
Attempt to assign property 'foo' of non-object
82+
Attempt to assign property 'foo' on bool
83+
Attempt to assign property 'foo' on bool

Zend/tests/bug31098.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ ok
4444
ok
4545
ok
4646

47-
Warning: Trying to get property 'wrong' of non-object in %s on line %d
47+
Warning: Attempt to read property 'wrong' on string in %s on line %d
4848
ok
4949

5050
Warning: Illegal string offset 'wrong' in %s on line %d

Zend/tests/bug44660.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Bug #44660 (Indexed and reference assignment to property of non-object don't tri
55
$s = "hello";
66
$a = true;
77

8-
echo "--> read access: ";
8+
echo "--> read access:";
99
echo $a->p;
1010

1111
echo "\n--> direct assignment:\n";
@@ -47,23 +47,23 @@ echo "\n--> Confirm assignments have had no impact:\n";
4747
var_dump($a);
4848
?>
4949
--EXPECTF--
50-
--> read access:
51-
Warning: Trying to get property 'p' of non-object in %s on line %d
50+
--> read access:
51+
Warning: Attempt to read property 'p' on bool in %s on line %d
5252

5353
--> direct assignment:
54-
Attempt to assign property 'p' of non-object
54+
Attempt to assign property 'p' on bool
5555

5656
--> increment:
57-
Attempt to increment/decrement property 'p' of non-object
57+
Attempt to increment/decrement property 'p' on bool
5858

5959
--> reference assignment:
60-
Attempt to modify property 'p' of non-object
60+
Attempt to modify property 'p' on bool
6161

6262
--> reference assignment:
63-
Attempt to modify property 'p' of non-object
63+
Attempt to modify property 'p' on bool
6464

6565
--> indexed assignment:
66-
Attempt to modify property 'p' of non-object
66+
Attempt to modify property 'p' on bool
6767

6868
--> Confirm assignments have had no impact:
6969
bool(true)

Zend/tests/bug47109.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ $a->{"a"."b"};
77
--EXPECTF--
88
Warning: Undefined variable $a in %s on line %d
99

10-
Warning: Trying to get property 'ab' of non-object in %s on line %d
10+
Warning: Attempt to read property 'ab' on null in %s on line %d

Zend/tests/bug52041.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,22 @@ var_dump(foo());
4848
?>
4949
--EXPECTF--
5050
Warning: Undefined variable $x in %s on line %d
51-
Attempt to assign property 'a' of non-object
51+
Attempt to assign property 'a' on null
5252

5353
Warning: Undefined variable $x in %s on line %d
54-
Attempt to modify property 'a' of non-object
54+
Attempt to modify property 'a' on null
5555

5656
Warning: Undefined variable $x in %s on line %d
57-
Attempt to increment/decrement property 'a' of non-object
57+
Attempt to increment/decrement property 'a' on null
5858

5959
Warning: Undefined variable $x in %s on line %d
60-
Attempt to modify property 'a' of non-object
60+
Attempt to modify property 'a' on null
6161

6262
Warning: Undefined variable $x in %s on line %d
63-
Attempt to assign property 'a' of non-object
63+
Attempt to assign property 'a' on null
6464

6565
Warning: Undefined variable $x in %s on line %d
66-
Attempt to modify property 'a' of non-object
66+
Attempt to modify property 'a' on null
6767

6868
Warning: Undefined variable $x in %s on line %d
6969

Zend/tests/bug52614.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ array(0) {
7575
}
7676
array(0) {
7777
}
78-
Attempt to assign property 'a' of non-object
78+
Attempt to assign property 'a' on null
7979
NULL
8080
object(stdClass)#3 (1) {
8181
["a"]=>

Zend/tests/bug75241.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ $d->d = &$d + $d->d/=0;
77
var_dump($d);
88
?>
99
--EXPECTF--
10-
Fatal error: Uncaught Error: Attempt to modify property 'd' of non-object in %s:%d
10+
Fatal error: Uncaught Error: Attempt to modify property 'd' on null in %s:%d
1111
Stack trace:
1212
#0 {main}
1313
thrown in %s on line %d

Zend/tests/bug75921.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ unset($null);
4545

4646
?>
4747
--EXPECTF--
48-
Attempt to assign property 'a' of non-object
48+
Attempt to assign property 'a' on null
4949

5050
Warning: Undefined variable $null in %s on line %d
5151
NULL
52-
Attempt to modify property 'a' of non-object
52+
Attempt to modify property 'a' on null
5353

5454
Warning: Undefined variable $null in %s on line %d
5555
NULL
56-
Attempt to modify property 'a' of non-object
56+
Attempt to modify property 'a' on null
5757

5858
Warning: Undefined variable $null in %s on line %d
5959
NULL
60-
Attempt to modify property 'a' of non-object
60+
Attempt to modify property 'a' on null
6161

6262
Warning: Undefined variable $null in %s on line %d
6363
NULL
64-
Attempt to modify property 'a' of non-object
64+
Attempt to modify property 'a' on null
6565

6666
Warning: Undefined variable $null in %s on line %d
6767
NULL

Zend/tests/bug76667.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ class T {
1313
{
1414
return $this->$v /= 0;
1515
}
16-
};
16+
}
1717

1818
$x = new T;
1919
$x->x = 1;
2020
?>
2121
--EXPECTF--
2222
Warning: Undefined variable $undefined in %s on line %d
2323

24-
Warning: Trying to get property '1' of non-object in %s on line %d
24+
Warning: Attempt to read property '1' on null in %s on line %d
2525

26-
Warning: Division by zero in %sbug76667.php on line %d
26+
Warning: Division by zero in %s on line %d
2727

2828
Warning: Undefined variable $undefined in %s on line %d
2929

30-
Warning: Trying to get property 'NAN' of non-object in %s on line %d
30+
Warning: Attempt to read property 'NAN' on null in %s on line %d
3131

32-
Warning: Division by zero in %sbug76667.php on line %d
32+
Warning: Division by zero in %s on line %d
3333

3434
Warning: Undefined variable $undefined in %s on line %d
3535

36-
Warning: Trying to get property 'NAN' of non-object in %s on line %d
36+
Warning: Attempt to read property 'NAN' on null in %s on line %d
3737

38-
Warning: Division by zero in %sbug76667.php on line %d
38+
Warning: Division by zero in %s on line %d

Zend/tests/bug78182.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ try {
1212
var_dump($var);
1313
?>
1414
--EXPECT--
15-
Attempt to modify property 'prop' of non-object
15+
Attempt to modify property 'prop' on null
1616
NULL

Zend/tests/bug78531.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ try {
2525
?>
2626
--EXPECTF--
2727
Warning: Undefined variable $u1 in %s on line %d
28-
Attempt to assign property 'a' of non-object
28+
Attempt to assign property 'a' on null
2929

3030
Warning: Undefined variable $u2 in %s on line %d
31-
Attempt to increment/decrement property 'a' of non-object
31+
Attempt to increment/decrement property 'a' on null
3232

3333
Warning: Undefined variable $u3 in %s on line %d
34-
Attempt to increment/decrement property 'a' of non-object
34+
Attempt to increment/decrement property 'a' on null
3535

3636
Warning: Undefined variable $u4 in %s on line %d
37-
Attempt to modify property 'a' of non-object
37+
Attempt to modify property 'a' on null

Zend/tests/dereference_014.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ var_dump($h);
2929
--EXPECTF--
3030
Warning: Trying to access array offset on value of type null in %s on line %d
3131

32-
Warning: Trying to get property 'a' of non-object in %s on line %d
32+
Warning: Attempt to read property 'a' on null in %s on line %d
3333
NULL
3434

3535
Warning: Trying to access array offset on value of type null in %s on line %d
3636

37-
Warning: Trying to get property 'b' of non-object in %s on line %d
37+
Warning: Attempt to read property 'b' on null in %s on line %d
3838
NULL

Zend/tests/isset_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Warning: Undefined variable $d in %s on line %d
3535

3636
Warning: Trying to access array offset on value of type null in %s on line %d
3737

38-
Warning: Trying to get property '' of non-object in %s on line %d
38+
Warning: Attempt to read property '' on string in %s on line %d
3939
bool(false)
4040
bool(true)
4141
bool(false)

Zend/tests/varSyntax/encapsed_string_deref.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var_dump("foo$bar"());
2222
--EXPECTF--
2323
string(1) "f"
2424

25-
Warning: Trying to get property 'prop' of non-object in %s on line %d
25+
Warning: Attempt to read property 'prop' on string in %s on line %d
2626
NULL
2727
Call to a member function method() on string
2828
int(42)

Zend/tests/varSyntax/magic_const_deref.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ test();
1919
--EXPECTF--
2020
string(1) "t"
2121

22-
Warning: Trying to get property 'prop' of non-object in %s on line %d
22+
Warning: Attempt to read property 'prop' on string in %s on line %d
2323
NULL
2424
Call to a member function method() on string

Zend/tests/varSyntax/propertyOfStringError.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Cannot take property of a string
77

88
?>
99
--EXPECTF--
10-
Warning: Trying to get property 'bar' of non-object in %s on line %d
10+
Warning: Attempt to read property 'bar' on string in %s on line %d

Zend/zend_execute.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,17 +621,22 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_erro
621621
|| opline->opcode == ZEND_POST_INC_OBJ
622622
|| opline->opcode == ZEND_POST_DEC_OBJ) {
623623
zend_throw_error(NULL,
624-
"Attempt to increment/decrement property '%s' of non-object",
625-
ZSTR_VAL(property_name));
624+
"Attempt to increment/decrement property '%s' on %s",
625+
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
626+
);
626627
} else if (opline->opcode == ZEND_FETCH_OBJ_W
627628
|| opline->opcode == ZEND_FETCH_OBJ_RW
628629
|| opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG
629630
|| opline->opcode == ZEND_ASSIGN_OBJ_REF) {
630631
zend_throw_error(NULL,
631-
"Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name));
632+
"Attempt to modify property '%s' on %s",
633+
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
634+
);
632635
} else {
633636
zend_throw_error(NULL,
634-
"Attempt to assign property '%s' of non-object", ZSTR_VAL(property_name));
637+
"Attempt to assign property '%s' on %s",
638+
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
639+
);
635640
}
636641
zend_tmp_string_release(tmp_property_name);
637642

@@ -1494,11 +1499,13 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D)
14941499
zend_throw_error(NULL, "%s", msg);
14951500
}
14961501

1497-
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(zval *property)
1502+
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(zval *object, zval *property)
14981503
{
14991504
zend_string *tmp_property_name;
15001505
zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name);
1501-
zend_error(E_WARNING, "Trying to get property '%s' of non-object", ZSTR_VAL(property_name));
1506+
zend_error(E_WARNING, "Attempt to read property '%s' on %s",
1507+
ZSTR_VAL(property_name), Z_ISUNDEF_P(object) ? "null" : zend_zval_type_name(object)
1508+
);
15021509
zend_tmp_string_release(tmp_property_name);
15031510
}
15041511

Zend/zend_vm_def.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ ZEND_VM_HOT_OBJ_HANDLER(82, ZEND_FETCH_OBJ_R, CONST|TMPVAR|UNUSED|THIS|CV, CONST
20142014
if (OP2_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) {
20152015
ZVAL_UNDEFINED_OP2();
20162016
}
2017-
zend_wrong_property_read(offset);
2017+
zend_wrong_property_read(container, offset);
20182018
ZVAL_NULL(EX_VAR(opline->result.var));
20192019
ZEND_VM_C_GOTO(fetch_obj_r_finish);
20202020
} while (0);

0 commit comments

Comments
 (0)