Skip to content

Improve error message for deprecated methods and invalid property access #5446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Zend/tests/024.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Zend/tests/026.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions Zend/tests/033.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Zend/tests/assign_dim_obj_null_return.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/bug31098.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Zend/tests/bug44660.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion Zend/tests/bug47109.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions Zend/tests/bug52041.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug52614.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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"]=>
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/bug75241.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 5 additions & 5 deletions Zend/tests/bug75921.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions Zend/tests/bug76667.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ class T {
{
return $this->$v /= 0;
}
};
}

$x = new T;
$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
2 changes: 1 addition & 1 deletion Zend/tests/bug78182.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions Zend/tests/bug78531.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Zend/tests/dereference_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/isset_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/varSyntax/encapsed_string_deref.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/varSyntax/magic_const_deref.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Zend/tests/varSyntax/propertyOfStringError.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
/* }}} */

Expand Down
17 changes: 11 additions & 6 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading