diff options
author | Nikita Popov <nikic@php.net> | 2015-06-20 15:09:58 +0200 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2015-06-20 15:09:58 +0200 |
commit | 9fa70dbd29f91c9ae9360f19c63ada18268f5b17 (patch) | |
tree | ddbfa628594b86a6bb6d53dc9a23a949500acc8b /Zend/zend_execute.c | |
parent | 257054e81d4dad73bf9d09cd206d3a6727ad1777 (diff) | |
download | php-git-9fa70dbd29f91c9ae9360f19c63ada18268f5b17.tar.gz |
Fixed bug #69889
There is one case that requires further discussion:
$foo = "test";
var_dump($foo[0.0] ?? "default");
var_dump(isset($foo[0.0]) ? $foo[0.0] : "default");
Here the former will currently return "t", while the latter also
returns "t" and additionally throws a notice.
I think we need to revisit the behavior of invalid types for string
offset access in PHP 7, as currently there is some mismatch between
what isset() does and what the access itself supports.
Diffstat (limited to 'Zend/zend_execute.c')
-rw-r--r-- | Zend/zend_execute.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 9190eff2c3..a62ff55c69 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1781,9 +1781,11 @@ try_string_offset: if (IS_LONG == is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), NULL, NULL, -1)) { break; } - if (type != BP_VAR_IS) { - zend_error(E_WARNING, "Illegal string offset '%s'", Z_STRVAL_P(dim)); + if (type == BP_VAR_IS) { + ZVAL_NULL(result); + return; } + zend_error(E_WARNING, "Illegal string offset '%s'", Z_STRVAL_P(dim)); break; case IS_DOUBLE: case IS_NULL: @@ -1809,8 +1811,10 @@ try_string_offset: if (UNEXPECTED(offset < 0) || UNEXPECTED(Z_STRLEN_P(container) <= (size_t)offset)) { if (type != BP_VAR_IS) { zend_error(E_NOTICE, "Uninitialized string offset: %pd", offset); + ZVAL_EMPTY_STRING(result); + } else { + ZVAL_NULL(result); } - ZVAL_EMPTY_STRING(result); } else { zend_uchar c = (zend_uchar)Z_STRVAL_P(container)[offset]; |