From 1179686f62cf976c8bccc7564e5ed41a3c5eb3a5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Fri, 24 Apr 2020 10:58:46 +0200 Subject: [PATCH] Improve error messages for invalid property access Closes GH-5446 Co-authored-by: Nikita Popov --- Zend/tests/024.phpt | 8 +++---- Zend/tests/026.phpt | 4 ++-- Zend/tests/033.phpt | 6 ++--- Zend/tests/assign_dim_obj_null_return.phpt | 4 ++-- Zend/tests/bug31098.phpt | 2 +- Zend/tests/bug44660.phpt | 16 ++++++------- Zend/tests/bug47109.phpt | 2 +- Zend/tests/bug52041.phpt | 12 +++++----- Zend/tests/bug52614.phpt | 2 +- Zend/tests/bug75241.phpt | 2 +- Zend/tests/bug75921.phpt | 10 ++++---- Zend/tests/bug76667.phpt | 14 +++++------ Zend/tests/bug78182.phpt | 2 +- Zend/tests/bug78531.phpt | 8 +++---- Zend/tests/dereference_014.phpt | 4 ++-- Zend/tests/isset_003.phpt | 2 +- .../varSyntax/encapsed_string_deref.phpt | 2 +- Zend/tests/varSyntax/magic_const_deref.phpt | 2 +- .../varSyntax/propertyOfStringError.phpt | 2 +- Zend/zend_API.c | 3 ++- Zend/zend_execute.c | 17 ++++++++----- Zend/zend_vm_def.h | 2 +- Zend/zend_vm_execute.h | 24 +++++++++---------- ext/dom/tests/bug47430.phpt | 4 ++-- ext/dom/tests/bug67949.phpt | 4 ++-- ext/libxml/tests/bug61367-read.phpt | 4 ++-- ext/opcache/jit/zend_jit_disasm_x86.c | 1 + ext/opcache/jit/zend_jit_helpers.c | 8 +++++-- ext/opcache/jit/zend_jit_x86.dasc | 20 ++++------------ .../tests/assign_obj_op_of_fetch_dim.phpt | 2 +- ext/opcache/tests/jit/fetch_obj_001.phpt | 6 ++--- ext/pdo_mysql/tests/bug44327.phpt | 2 +- 32 files changed, 101 insertions(+), 100 deletions(-) diff --git a/Zend/tests/024.phpt b/Zend/tests/024.phpt index 5d8d55e6fa..798ba73214 100644 --- a/Zend/tests/024.phpt +++ b/Zend/tests/024.phpt @@ -41,17 +41,17 @@ NULL Warning: Undefined variable $b in %s on line %d int(1) -Warning: Trying to get property '1' of non-object in %s on line %d +Warning: Attempt to read property '1' on int in %s on line %d NULL -Warning: Trying to get property '1' of non-object in %s on line %d +Warning: Attempt to read property '1' on int in %s on line %d NULL Warning: Undefined variable $c in %s on line %d Warning: Trying to access array offset on value of type null in %s on line %d -Warning: Trying to get property '1' of non-object in %s on line %d +Warning: Attempt to read property '1' on int in %s on line %d -Warning: Trying to get property '' of non-object in %s on line %d +Warning: Attempt to read property '' on null in %s on line %d NULL diff --git a/Zend/tests/026.phpt b/Zend/tests/026.phpt index 9008abb791..6c2b206184 100644 --- a/Zend/tests/026.phpt +++ b/Zend/tests/026.phpt @@ -22,7 +22,7 @@ print "ok\n"; ?> --EXPECTF-- -Warning: Trying to get property 'a' of non-object in %s on line %d +Warning: Attempt to read property 'a' on null in %s on line %d ok -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null ok diff --git a/Zend/tests/033.phpt b/Zend/tests/033.phpt index 75ae71a674..8247b5907e 100644 --- a/Zend/tests/033.phpt +++ b/Zend/tests/033.phpt @@ -61,6 +61,6 @@ Warning: Trying to access array offset on value of type null in %s on line %d Warning: Trying to access array offset on value of type null in %s on line %d -Warning: Trying to get property 'foo' of non-object in %s on line %d -Attempt to assign property 'foo' of non-object -Attempt to assign property 'bar' of non-object +Warning: Attempt to read property 'foo' on null in %s on line %d +Attempt to assign property 'foo' on null +Attempt to assign property 'bar' on null diff --git a/Zend/tests/assign_dim_obj_null_return.phpt b/Zend/tests/assign_dim_obj_null_return.phpt index 1641992a0c..1f1a5a9862 100644 --- a/Zend/tests/assign_dim_obj_null_return.phpt +++ b/Zend/tests/assign_dim_obj_null_return.phpt @@ -79,5 +79,5 @@ Cannot add element to the array as the next element is already occupied Illegal offset type Illegal offset type Cannot use a scalar value as an array -Attempt to assign property 'foo' of non-object -Attempt to assign property 'foo' of non-object +Attempt to assign property 'foo' on bool +Attempt to assign property 'foo' on bool diff --git a/Zend/tests/bug31098.phpt b/Zend/tests/bug31098.phpt index 3276782c01..4d01d36cd8 100644 --- a/Zend/tests/bug31098.phpt +++ b/Zend/tests/bug31098.phpt @@ -44,7 +44,7 @@ ok ok ok -Warning: Trying to get property 'wrong' of non-object in %s on line %d +Warning: Attempt to read property 'wrong' on string in %s on line %d ok Warning: Illegal string offset 'wrong' in %s on line %d diff --git a/Zend/tests/bug44660.phpt b/Zend/tests/bug44660.phpt index fbe4a90dcd..5097fa7518 100644 --- a/Zend/tests/bug44660.phpt +++ b/Zend/tests/bug44660.phpt @@ -5,7 +5,7 @@ Bug #44660 (Indexed and reference assignment to property of non-object don't tri $s = "hello"; $a = true; -echo "--> read access: "; +echo "--> read access:"; echo $a->p; echo "\n--> direct assignment:\n"; @@ -47,23 +47,23 @@ echo "\n--> Confirm assignments have had no impact:\n"; var_dump($a); ?> --EXPECTF-- ---> read access: -Warning: Trying to get property 'p' of non-object in %s on line %d +--> read access: +Warning: Attempt to read property 'p' on bool in %s on line %d --> direct assignment: -Attempt to assign property 'p' of non-object +Attempt to assign property 'p' on bool --> increment: -Attempt to increment/decrement property 'p' of non-object +Attempt to increment/decrement property 'p' on bool --> reference assignment: -Attempt to modify property 'p' of non-object +Attempt to modify property 'p' on bool --> reference assignment: -Attempt to modify property 'p' of non-object +Attempt to modify property 'p' on bool --> indexed assignment: -Attempt to modify property 'p' of non-object +Attempt to modify property 'p' on bool --> Confirm assignments have had no impact: bool(true) diff --git a/Zend/tests/bug47109.phpt b/Zend/tests/bug47109.phpt index b796c420bd..ed1c6d706e 100644 --- a/Zend/tests/bug47109.phpt +++ b/Zend/tests/bug47109.phpt @@ -7,4 +7,4 @@ $a->{"a"."b"}; --EXPECTF-- Warning: Undefined variable $a in %s on line %d -Warning: Trying to get property 'ab' of non-object in %s on line %d +Warning: Attempt to read property 'ab' on null in %s on line %d diff --git a/Zend/tests/bug52041.phpt b/Zend/tests/bug52041.phpt index 8068b2d451..bc5297c8d3 100644 --- a/Zend/tests/bug52041.phpt +++ b/Zend/tests/bug52041.phpt @@ -48,22 +48,22 @@ var_dump(foo()); ?> --EXPECTF-- Warning: Undefined variable $x in %s on line %d -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null Warning: Undefined variable $x in %s on line %d -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $x in %s on line %d -Attempt to increment/decrement property 'a' of non-object +Attempt to increment/decrement property 'a' on null Warning: Undefined variable $x in %s on line %d -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $x in %s on line %d -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null Warning: Undefined variable $x in %s on line %d -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $x in %s on line %d diff --git a/Zend/tests/bug52614.phpt b/Zend/tests/bug52614.phpt index 30c1fc488a..955d873d8c 100644 --- a/Zend/tests/bug52614.phpt +++ b/Zend/tests/bug52614.phpt @@ -75,7 +75,7 @@ array(0) { } array(0) { } -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null NULL object(stdClass)#3 (1) { ["a"]=> diff --git a/Zend/tests/bug75241.phpt b/Zend/tests/bug75241.phpt index d6c2d79e2d..832ca44024 100644 --- a/Zend/tests/bug75241.phpt +++ b/Zend/tests/bug75241.phpt @@ -7,7 +7,7 @@ $d->d = &$d + $d->d/=0; var_dump($d); ?> --EXPECTF-- -Fatal error: Uncaught Error: Attempt to modify property 'd' of non-object in %s:%d +Fatal error: Uncaught Error: Attempt to modify property 'd' on null in %s:%d Stack trace: #0 {main} thrown in %s on line %d diff --git a/Zend/tests/bug75921.phpt b/Zend/tests/bug75921.phpt index c309266d93..cb016b7844 100644 --- a/Zend/tests/bug75921.phpt +++ b/Zend/tests/bug75921.phpt @@ -45,23 +45,23 @@ unset($null); ?> --EXPECTF-- -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null Warning: Undefined variable $null in %s on line %d NULL -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $null in %s on line %d NULL -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $null in %s on line %d NULL -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $null in %s on line %d NULL -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null Warning: Undefined variable $null in %s on line %d NULL diff --git a/Zend/tests/bug76667.phpt b/Zend/tests/bug76667.phpt index 259329722e..73d12de525 100644 --- a/Zend/tests/bug76667.phpt +++ b/Zend/tests/bug76667.phpt @@ -13,7 +13,7 @@ class T { { return $this->$v /= 0; } -}; +} $x = new T; $x->x = 1; @@ -21,18 +21,18 @@ $x->x = 1; --EXPECTF-- Warning: Undefined variable $undefined in %s on line %d -Warning: Trying to get property '1' of non-object in %s on line %d +Warning: Attempt to read property '1' on null in %s on line %d -Warning: Division by zero in %sbug76667.php on line %d +Warning: Division by zero in %s on line %d Warning: Undefined variable $undefined in %s on line %d -Warning: Trying to get property 'NAN' of non-object in %s on line %d +Warning: Attempt to read property 'NAN' on null in %s on line %d -Warning: Division by zero in %sbug76667.php on line %d +Warning: Division by zero in %s on line %d Warning: Undefined variable $undefined in %s on line %d -Warning: Trying to get property 'NAN' of non-object in %s on line %d +Warning: Attempt to read property 'NAN' on null in %s on line %d -Warning: Division by zero in %sbug76667.php on line %d +Warning: Division by zero in %s on line %d diff --git a/Zend/tests/bug78182.phpt b/Zend/tests/bug78182.phpt index d7f10e94df..1f9a8b8530 100644 --- a/Zend/tests/bug78182.phpt +++ b/Zend/tests/bug78182.phpt @@ -12,5 +12,5 @@ try { var_dump($var); ?> --EXPECT-- -Attempt to modify property 'prop' of non-object +Attempt to modify property 'prop' on null NULL diff --git a/Zend/tests/bug78531.phpt b/Zend/tests/bug78531.phpt index 682ff50c5b..9ddcbf3724 100644 --- a/Zend/tests/bug78531.phpt +++ b/Zend/tests/bug78531.phpt @@ -25,13 +25,13 @@ try { ?> --EXPECTF-- Warning: Undefined variable $u1 in %s on line %d -Attempt to assign property 'a' of non-object +Attempt to assign property 'a' on null Warning: Undefined variable $u2 in %s on line %d -Attempt to increment/decrement property 'a' of non-object +Attempt to increment/decrement property 'a' on null Warning: Undefined variable $u3 in %s on line %d -Attempt to increment/decrement property 'a' of non-object +Attempt to increment/decrement property 'a' on null Warning: Undefined variable $u4 in %s on line %d -Attempt to modify property 'a' of non-object +Attempt to modify property 'a' on null diff --git a/Zend/tests/dereference_014.phpt b/Zend/tests/dereference_014.phpt index c6f21ab0ed..7b115cf48a 100644 --- a/Zend/tests/dereference_014.phpt +++ b/Zend/tests/dereference_014.phpt @@ -29,10 +29,10 @@ var_dump($h); --EXPECTF-- Warning: Trying to access array offset on value of type null in %s on line %d -Warning: Trying to get property 'a' of non-object in %s on line %d +Warning: Attempt to read property 'a' on null in %s on line %d NULL Warning: Trying to access array offset on value of type null in %s on line %d -Warning: Trying to get property 'b' of non-object in %s on line %d +Warning: Attempt to read property 'b' on null in %s on line %d NULL diff --git a/Zend/tests/isset_003.phpt b/Zend/tests/isset_003.phpt index dc7f045de3..4812d8e394 100644 --- a/Zend/tests/isset_003.phpt +++ b/Zend/tests/isset_003.phpt @@ -35,7 +35,7 @@ Warning: Undefined variable $d in %s on line %d Warning: Trying to access array offset on value of type null in %s on line %d -Warning: Trying to get property '' of non-object in %s on line %d +Warning: Attempt to read property '' on string in %s on line %d bool(false) bool(true) bool(false) diff --git a/Zend/tests/varSyntax/encapsed_string_deref.phpt b/Zend/tests/varSyntax/encapsed_string_deref.phpt index e880f0f1ff..10af3c1158 100644 --- a/Zend/tests/varSyntax/encapsed_string_deref.phpt +++ b/Zend/tests/varSyntax/encapsed_string_deref.phpt @@ -22,7 +22,7 @@ var_dump("foo$bar"()); --EXPECTF-- string(1) "f" -Warning: Trying to get property 'prop' of non-object in %s on line %d +Warning: Attempt to read property 'prop' on string in %s on line %d NULL Call to a member function method() on string int(42) diff --git a/Zend/tests/varSyntax/magic_const_deref.phpt b/Zend/tests/varSyntax/magic_const_deref.phpt index 28ca4b7f40..dc293ba6ab 100644 --- a/Zend/tests/varSyntax/magic_const_deref.phpt +++ b/Zend/tests/varSyntax/magic_const_deref.phpt @@ -19,6 +19,6 @@ test(); --EXPECTF-- string(1) "t" -Warning: Trying to get property 'prop' of non-object in %s on line %d +Warning: Attempt to read property 'prop' on string in %s on line %d NULL Call to a member function method() on string diff --git a/Zend/tests/varSyntax/propertyOfStringError.phpt b/Zend/tests/varSyntax/propertyOfStringError.phpt index 446f1372cd..2d47fd5c4d 100644 --- a/Zend/tests/varSyntax/propertyOfStringError.phpt +++ b/Zend/tests/varSyntax/propertyOfStringError.phpt @@ -7,4 +7,4 @@ Cannot take property of a string ?> --EXPECTF-- -Warning: Trying to get property 'bar' of non-object in %s on line %d +Warning: Attempt to read property 'bar' on string in %s on line %d diff --git a/Zend/zend_API.c b/Zend/zend_API.c index 01f9277214..cd72a6f156 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -133,7 +133,8 @@ ZEND_API const char *zend_get_type_by_const(int type) /* {{{ */ ZEND_API const char *zend_zval_type_name(const zval *arg) /* {{{ */ { ZVAL_DEREF(arg); - return zend_get_type_by_const(Z_TYPE_P(arg)); + + return Z_ISUNDEF_P(arg) ? "null" : zend_get_type_by_const(Z_TYPE_P(arg)); } /* }}} */ diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 2eb7b17260..f302363621 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -621,17 +621,22 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_throw_non_object_erro || opline->opcode == ZEND_POST_INC_OBJ || opline->opcode == ZEND_POST_DEC_OBJ) { zend_throw_error(NULL, - "Attempt to increment/decrement property '%s' of non-object", - ZSTR_VAL(property_name)); + "Attempt to increment/decrement property '%s' on %s", + ZSTR_VAL(property_name), zend_zval_type_name(object) + ); } else if (opline->opcode == ZEND_FETCH_OBJ_W || opline->opcode == ZEND_FETCH_OBJ_RW || opline->opcode == ZEND_FETCH_OBJ_FUNC_ARG || opline->opcode == ZEND_ASSIGN_OBJ_REF) { zend_throw_error(NULL, - "Attempt to modify property '%s' of non-object", ZSTR_VAL(property_name)); + "Attempt to modify property '%s' on %s", + ZSTR_VAL(property_name), zend_zval_type_name(object) + ); } else { zend_throw_error(NULL, - "Attempt to assign property '%s' of non-object", ZSTR_VAL(property_name)); + "Attempt to assign property '%s' on %s", + ZSTR_VAL(property_name), zend_zval_type_name(object) + ); } zend_tmp_string_release(tmp_property_name); @@ -1494,11 +1499,11 @@ static zend_never_inline ZEND_COLD void zend_wrong_string_offset(EXECUTE_DATA_D) zend_throw_error(NULL, "%s", msg); } -static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(zval *property) +static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_wrong_property_read(zval *object, zval *property) { zend_string *tmp_property_name; zend_string *property_name = zval_get_tmp_string(property, &tmp_property_name); - zend_error(E_WARNING, "Trying to get property '%s' of non-object", ZSTR_VAL(property_name)); + zend_error(E_WARNING, "Attempt to read property '%s' on %s", ZSTR_VAL(property_name), zend_zval_type_name(object)); zend_tmp_string_release(tmp_property_name); } diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index de0dfa2f35..9cccd2e2f9 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2014,7 +2014,7 @@ ZEND_VM_HOT_OBJ_HANDLER(82, ZEND_FETCH_OBJ_R, CONST|TMPVAR|UNUSED|THIS|CV, CONST if (OP2_TYPE == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); ZEND_VM_C_GOTO(fetch_obj_r_finish); } while (0); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 0bf16a6fee..1c10b8ccbf 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -5220,7 +5220,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_ if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -7395,7 +7395,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_ if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -9651,7 +9651,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_ if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -13970,7 +13970,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_TMPVAR_CONST_ if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -15351,7 +15351,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_TMPVAR_TMPVAR if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -16626,7 +16626,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_TMPVAR_CV_HAN if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -29416,7 +29416,7 @@ static zend_always_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -31288,7 +31288,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_UNUSED_TMPVAR if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -33683,7 +33683,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_UNUSED_CV_HAN if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -37989,7 +37989,7 @@ static zend_always_inline ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R if (IS_CONST == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -41471,7 +41471,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_CV_TMPVAR_HAN if ((IS_TMP_VAR|IS_VAR) == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); @@ -46279,7 +46279,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_FETCH_OBJ_R_SPEC_CV_CV_HANDLER if (IS_CV == IS_CV && UNEXPECTED(Z_TYPE_P(offset) == IS_UNDEF)) { ZVAL_UNDEFINED_OP2(); } - zend_wrong_property_read(offset); + zend_wrong_property_read(container, offset); ZVAL_NULL(EX_VAR(opline->result.var)); goto fetch_obj_r_finish; } while (0); diff --git a/ext/dom/tests/bug47430.phpt b/ext/dom/tests/bug47430.phpt index 7be332ecc1..2d5733fe31 100644 --- a/ext/dom/tests/bug47430.phpt +++ b/ext/dom/tests/bug47430.phpt @@ -25,8 +25,8 @@ print_r($arr); ?> --EXPECT-- -Attempt to assign property 'nodeValue' of non-object -Attempt to assign property 'nodeValue' of non-object +Attempt to assign property 'nodeValue' on null +Attempt to assign property 'nodeValue' on null Array ( [0] => Value diff --git a/ext/dom/tests/bug67949.phpt b/ext/dom/tests/bug67949.phpt index c49f0e4e0e..f6a12b9812 100644 --- a/ext/dom/tests/bug67949.phpt +++ b/ext/dom/tests/bug67949.phpt @@ -62,7 +62,7 @@ bool(false) testing property access string(4) "data" -Warning: Trying to get property 'textContent' of non-object in %s on line %d +Warning: Attempt to read property 'textContent' on null in %s on line %d NULL testing offset not a long array(1) { @@ -70,7 +70,7 @@ array(1) { string(4) "test" } -Warning: Trying to get property 'textContent' of non-object in %s on line %d +Warning: Attempt to read property 'textContent' on null in %s on line %d bool(false) NULL array(1) { diff --git a/ext/libxml/tests/bug61367-read.phpt b/ext/libxml/tests/bug61367-read.phpt index 97b6513094..2dd8ca7c21 100644 --- a/ext/libxml/tests/bug61367-read.phpt +++ b/ext/libxml/tests/bug61367-read.phpt @@ -58,6 +58,6 @@ Warning: DOMDocument::loadXML(): Failure to process entity file in Entity, line: Warning: DOMDocument::loadXML(): Entity 'file' not defined in Entity, line: 4 in %s on line %d -Warning: Trying to get property 'firstChild' of non-object in %s on line %d +Warning: Attempt to read property 'firstChild' on null in %s on line %d -Warning: Trying to get property 'nodeValue' of non-object in %s on line %d +Warning: Attempt to read property 'nodeValue' on null in %s on line %d diff --git a/ext/opcache/jit/zend_jit_disasm_x86.c b/ext/opcache/jit/zend_jit_disasm_x86.c index 44b23e1a19..99de6145e2 100644 --- a/ext/opcache/jit/zend_jit_disasm_x86.c +++ b/ext/opcache/jit/zend_jit_disasm_x86.c @@ -448,6 +448,7 @@ static int zend_jit_disasm_init(void) REGISTER_HELPER(zend_jit_assign_op_to_typed_ref); REGISTER_HELPER(zend_jit_only_vars_by_reference); REGISTER_HELPER(zend_jit_invalid_array_access); + REGISTER_HELPER(zend_jit_invalid_property_read); REGISTER_HELPER(zend_jit_prepare_assign_dim_ref); REGISTER_HELPER(zend_jit_pre_inc); REGISTER_HELPER(zend_jit_pre_dec); diff --git a/ext/opcache/jit/zend_jit_helpers.c b/ext/opcache/jit/zend_jit_helpers.c index 3bfce1a854..ed7708126c 100644 --- a/ext/opcache/jit/zend_jit_helpers.c +++ b/ext/opcache/jit/zend_jit_helpers.c @@ -1506,8 +1506,12 @@ static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg) static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container) { - const char *type = Z_ISUNDEF_P(container) ? "null" : zend_zval_type_name(container); - zend_error(E_WARNING, "Trying to access array offset on value of type %s", type); + zend_error(E_WARNING, "Trying to access array offset on value of type %s", zend_zval_type_name(container)); +} + +static void ZEND_FASTCALL zend_jit_invalid_property_read(zval *container, const char *property_name) +{ + zend_error(E_WARNING, "Attempt to read property '%s' on %s", property_name, zend_zval_type_name(container)); } static zval * ZEND_FASTCALL zend_jit_prepare_assign_dim_ref(zval *ref) { diff --git a/ext/opcache/jit/zend_jit_x86.dasc b/ext/opcache/jit/zend_jit_x86.dasc index 4af3481c51..34d92e4347 100644 --- a/ext/opcache/jit/zend_jit_x86.dasc +++ b/ext/opcache/jit/zend_jit_x86.dasc @@ -10537,7 +10537,7 @@ static int zend_jit_fetch_obj_read(dasm_State **Dst, const zend_op *opline, cons zval *member; uint32_t offset; zend_bool may_be_dynamic = 1; - zend_jit_addr op1_addr = 0; + zend_jit_addr op1_addr = 0, orig_op1_addr = 0; zend_jit_addr res_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, opline->result.var); zend_jit_addr this_addr = ZEND_ADDR_MEM_ZVAL(ZREG_FP, offsetof(zend_execute_data, This)); zend_jit_addr prop_addr; @@ -10552,7 +10552,7 @@ static int zend_jit_fetch_obj_read(dasm_State **Dst, const zend_op *opline, cons if (opline->op1_type == IS_UNUSED) { | GET_ZVAL_PTR FCARG1a, this_addr } else { - op1_addr = OP1_ADDR(); + op1_addr = orig_op1_addr = OP1_ADDR(); if (op1_info & MAY_BE_REF) { | LOAD_ZVAL_ADDR r0, op1_addr | ZVAL_DEREF r0, op1_info @@ -10659,19 +10659,9 @@ static int zend_jit_fetch_obj_read(dasm_State **Dst, const zend_op *opline, cons | EXT_CALL zend_jit_undefined_op_helper, r0 |1: } - |.if X64 - | mov CARG1, E_WARNING - | LOAD_ADDR CARG2, "Trying to get property '%s' of non-object" - | LOAD_ADDR CARG3, Z_STRVAL_P(member) - | EXT_CALL zend_error, r0 - |.else - | sub r4, 4 - | push Z_STRVAL_P(member) - | push "Trying to get property '%s' of non-object" - | push E_WARNING - | EXT_CALL zend_error, r0 - | add r4, 16 - |.endif + | LOAD_ZVAL_ADDR FCARG1a, orig_op1_addr + | LOAD_ADDR FCARG2a, Z_STRVAL_P(member) + | EXT_CALL zend_jit_invalid_property_read, r0 } | SET_ZVAL_TYPE_INFO res_addr, IS_NULL | jmp >9 diff --git a/ext/opcache/tests/assign_obj_op_of_fetch_dim.phpt b/ext/opcache/tests/assign_obj_op_of_fetch_dim.phpt index 2c07051778..4b570baaaf 100644 --- a/ext/opcache/tests/assign_obj_op_of_fetch_dim.phpt +++ b/ext/opcache/tests/assign_obj_op_of_fetch_dim.phpt @@ -17,4 +17,4 @@ try { ?> --EXPECTF-- Notice: Undefined offset: 0 in %s on line %d -Attempt to assign property 'y' of non-object +Attempt to assign property 'y' on null diff --git a/ext/opcache/tests/jit/fetch_obj_001.phpt b/ext/opcache/tests/jit/fetch_obj_001.phpt index d309442187..49de772b66 100644 --- a/ext/opcache/tests/jit/fetch_obj_001.phpt +++ b/ext/opcache/tests/jit/fetch_obj_001.phpt @@ -128,10 +128,10 @@ object(stdClass)#%d (2) { array(0) { } } -Attempt to modify property 'abc' of non-object +Attempt to modify property 'abc' on array array(0) { } -Attempt to modify property 'abc' of non-object +Attempt to modify property 'abc' on null NULL -Attempt to modify property 'abc' of non-object +Attempt to modify property 'abc' on string string(0) "" diff --git a/ext/pdo_mysql/tests/bug44327.phpt b/ext/pdo_mysql/tests/bug44327.phpt index 5adc8209e7..4b0b7d9bd0 100644 --- a/ext/pdo_mysql/tests/bug44327.phpt +++ b/ext/pdo_mysql/tests/bug44327.phpt @@ -60,5 +60,5 @@ object(PDORow)#%d (2) { string(19) "SELECT id FROM test" ---------------------------------- -Warning: Trying to get property 'queryString' of non-object in %s on line %d +Warning: Attempt to read property 'queryString' on bool in %s on line %d NULL -- 2.40.0