com php-src: Fixed bug #69889: NEWS Zend/tests/bug69889.phpt Zend/zend_execute.c

From: Date: Sat, 20 Jun 2015 13:09:58 +0000
Subject: com php-src: Fixed bug #69889: NEWS Zend/tests/bug69889.phpt Zend/zend_execute.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-87404@lists.php.net to get a copy of this message
Commit: 9fa70dbd29f91c9ae9360f19c63ada18268f5b17 Author: Nikita Popov <nikic@php.net> Sat, 20 Jun 2015 15:09:58 +0200 Parents: 257054e81d4dad73bf9d09cd206d3a6727ad1777 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9fa70dbd29f91c9ae9360f19c63ada18268f5b17 Log: 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. Bugs: https://bugs.php.net/69889 Changed paths: M NEWS A Zend/tests/bug69889.phpt M Zend/zend_execute.c Diff: diff --git a/NEWS b/NEWS index c25ce52..a3c7709 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,8 @@ PHP NEWS 7/8/8.1/10 as "Business"). (Christian Wenz) . Fixes bug #69835 (phpinfo() does not report many Windows SKUs). (Christian Wenz) + . Fixed bug #69889 (Null coalesce operator doesn't work for string offsets). + (Nikita) - DOM: . Fixed bug #69846 (Segmenation fault (access violation) when iterating over diff --git a/Zend/tests/bug69889.phpt b/Zend/tests/bug69889.phpt new file mode 100644 index 0000000..8aae7c1 --- /dev/null +++ b/Zend/tests/bug69889.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #69889: Null coalesce operator doesn't work for string offsets +--FILE-- +<?php + +$foo = "test"; +var_dump($foo[0] ?? "default"); + +var_dump($foo[5] ?? "default"); +var_dump(isset($foo[5]) ? $foo[5] : "default"); + +var_dump($foo["str"] ?? "default"); +var_dump(isset($foo["str"]) ? $foo["str"] : "default"); + +?> +--EXPECT-- +string(1) "t" +string(7) "default" +string(7) "default" +string(7) "default" +string(7) "default" + diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 9190eff..a62ff55 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];

« previous php.cvs (#87404) next »