]> granicus.if.org Git - php/commitdiff
Fixed bug #74478
authorjhdxr <jhdxr@php.net>
Wed, 24 May 2017 16:00:48 +0000 (18:00 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 24 May 2017 16:01:41 +0000 (18:01 +0200)
NEWS
ext/spl/spl_fixedarray.c
ext/spl/tests/bug74478.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 1637b81388593cfe7cedf6f37262983b723b8fef..daab8dcc33f5a7e90c44a8e0a4a26c21d799c95b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -2,7 +2,9 @@ PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2017 PHP 7.0.21
 
-
+- SPL:
+  . Fixed bug #74478 (null coalescing operator failing with SplFixedArray).
+    (jhdxr)
 
 8 Jun 2017 PHP 7.0.20
 
index 87c59261c0589337e5aff386a981c960abea9b76..4426bb6e81f9a259cf6f9f61a0efee70af2d63f9 100644 (file)
@@ -358,6 +358,21 @@ static zval *spl_fixedarray_object_read_dimension(zval *object, zval *offset, in
 
        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 (intern->fptr_offset_get) {
                zval tmp;
                if (!offset) {
diff --git a/ext/spl/tests/bug74478.phpt b/ext/spl/tests/bug74478.phpt
new file mode 100644 (file)
index 0000000..da63984
--- /dev/null
@@ -0,0 +1,62 @@
+--TEST--\r
+Bug #74478: null coalescing operator failing with SplFixedArray\r
+--FILE--\r
+<?php\r
+\r
+class MyFixedArray extends \SplFixedArray\r
+{\r
+    public function offsetExists($name) {\r
+        echo "offsetExists($name)\n";\r
+        return parent::offsetExists($name);\r
+    }\r
+    public function offsetGet($name) {\r
+        echo "offsetGet($name)\n";\r
+        return parent::offsetGet($name);\r
+    }\r
+    public function offsetSet($name, $value) {\r
+        echo "offsetSet($name)\n";\r
+        return parent::offsetSet($name, $value);\r
+    }\r
+    public function offsetUnset($name) {\r
+        echo "offsetUnset($name)\n";\r
+        return parent::offsetUnset($name);\r
+    }\r
+\r
+};\r
+\r
+$fixedData = new MyFixedArray(10);\r
+var_dump(isset($fixedData[0][1][2]));\r
+var_dump(isset($fixedData[0]->foo));\r
+var_dump($fixedData[0] ?? 42);\r
+var_dump($fixedData[0][1][2] ?? 42);\r
+\r
+$fixedData[0] = new MyFixedArray(10);\r
+$fixedData[0][1] = new MyFixedArray(10);\r
+var_dump(isset($fixedData[0][1][2]));\r
+var_dump($fixedData[0][1][2] ?? 42);\r
+\r
+?>\r
+--EXPECT--\r
+offsetExists(0)\r
+bool(false)\r
+offsetExists(0)\r
+bool(false)\r
+offsetExists(0)\r
+int(42)\r
+offsetExists(0)\r
+int(42)\r
+offsetSet(0)\r
+offsetGet(0)\r
+offsetSet(1)\r
+offsetExists(0)\r
+offsetGet(0)\r
+offsetExists(1)\r
+offsetGet(1)\r
+offsetExists(2)\r
+bool(false)\r
+offsetExists(0)\r
+offsetGet(0)\r
+offsetExists(1)\r
+offsetGet(1)\r
+offsetExists(2)\r
+int(42)
\ No newline at end of file