]> granicus.if.org Git - php/commitdiff
Fix #79393: Null coalescing operator failing with SplFixedArray
authorChristoph M. Becker <cmbecker69@gmx.de>
Wed, 18 Mar 2020 16:39:27 +0000 (17:39 +0100)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 23 Mar 2020 12:29:25 +0000 (13:29 +0100)
We favor the KISS principle over optimization[1] – SPL is already
special enough.

[1] <https://github.com/php/php-src/pull/2489/commits/352f3d4476a79bb86136b431719df7394e5a8d4e#r112498098>ff

NEWS
ext/spl/spl_fixedarray.c
ext/spl/tests/bug79393.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5cc62b59b320e5781e2cebeba72d429ba0d36a9c..10b5b91fe5950957bcbc013ac32933ac2573926a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,8 @@ PHP                                                                        NEWS
 
 - Spl:
   . Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
+  . Fixed bug #79393 (Null coalescing operator failing with SplFixedArray).
+    (cmb)
 
 - Zip:
   . Fixed Bug #79296 (ZipArchive::open fails on empty file). (Remi)
index 392175f781fc71e6bae069dbb63f78a20dc9c02d..488731aa1fae0bb5eefb3b311e26282ce3a11ba2 100644 (file)
@@ -336,25 +336,16 @@ static inline zval *spl_fixedarray_object_read_dimension_helper(spl_fixedarray_o
 }
 /* }}} */
 
+static int spl_fixedarray_object_has_dimension(zval *object, zval *offset, int check_empty);
+
 static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, int type, zval *rv) /* {{{ */
 {
        spl_fixedarray_object *intern;
 
        intern = Z_SPLFIXEDARRAY_P(object);
 
-       if (type == BP_VAR_IS && intern->fptr_offset_has) {
-               SEPARATE_ARG_IF_REF(offset);
-               zend_call_method_with_1_params(object, intern->std.ce, &intern->fptr_offset_has, "offsetexists", rv, offset);
-               if (UNEXPECTED(Z_ISUNDEF_P(rv))) {
-                       zval_ptr_dtor(offset);
-                       return NULL;
-               }
-               if (!i_zend_is_true(rv)) {
-                       zval_ptr_dtor(offset);
-                       zval_ptr_dtor(rv);
-                       return &EG(uninitialized_zval);
-               }
-               zval_ptr_dtor(rv);
+       if (type == BP_VAR_IS && !spl_fixedarray_object_has_dimension(object, offset, 0)) {
+               return &EG(uninitialized_zval);
        }
 
        if (intern->fptr_offset_get) {
diff --git a/ext/spl/tests/bug79393.phpt b/ext/spl/tests/bug79393.phpt
new file mode 100644 (file)
index 0000000..e8036c7
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+Bug #79393 (Null coalescing operator failing with SplFixedArray)
+--FILE--
+<?php
+$foo = new SplFixedArray(5);
+$foo[0] = 'bar1';
+$foo[1] = 'bar2';
+$foo[2] = 0;
+$foo[3] = false;
+$foo[4] = '';
+
+var_dump($foo[0] ?? null);
+var_dump($foo[1] ?? null);
+var_dump($foo[2] ?? null);
+var_dump($foo[3] ?? null);
+var_dump($foo[4] ?? null);
+var_dump($foo[5] ?? null);
+?>
+--EXPECT--
+string(4) "bar1"
+string(4) "bar2"
+int(0)
+bool(false)
+string(0) ""
+NULL