Skip to content

Commit 1d35b17

Browse files
committed
Consistent error messages for unsetting a string offset
1 parent d9ecd94 commit 1d35b17

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Zend/tests/bug24773.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Bug #24773 (unset() of integers treated as arrays causes a crash)
66
unset($array["lvl1"]["lvl2"]["b"]);
77
?>
88
--EXPECTF--
9-
Fatal error: Uncaught TypeError: Cannot access offset of type string in unset in %s:%d
9+
Fatal error: Uncaught Error: Cannot unset string offsets in %s:%d
1010
Stack trace:
1111
#0 {main}
1212
thrown in %s on line %d

Zend/zend.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1728,7 +1728,12 @@ ZEND_API ZEND_COLD void zend_illegal_container_offset(const zend_string *contain
17281728
zend_zval_type_name(offset));
17291729
return;
17301730
case BP_VAR_UNSET:
1731-
zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset));
1731+
/* Consistent error for when trying to unset a string offset */
1732+
if (zend_string_equals(container, ZSTR_KNOWN(ZEND_STR_STRING))) {
1733+
zend_throw_error(NULL, "Cannot unset string offsets");
1734+
} else {
1735+
zend_type_error("Cannot access offset of type %s in unset", zend_zval_type_name(offset));
1736+
}
17321737
return;
17331738
default:
17341739
zend_type_error("Cannot access offset of type %s on %s",

0 commit comments

Comments
 (0)