com php-src: Fixed bug #74478: NEWS ext/spl/spl_fixedarray. c ext/spl/tests/bug74478.phpt

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    872e43d6e55e4af84681b259198ee688287cd40d
Author:    jhdxr <[email protected]>         Wed, 24 May 2017 18:00:48 +0200
Committer: Nikita Popov <[email protected]>      Wed, 24 May 2017 18:01:41 +0200
Parents:   fff1cab367c4d34a2fbf967708a31b49549b8dd7
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=872e43d6e55e4af84681b259198ee688287cd40d

Log:
Fixed bug #74478

Bugs:
https://bugs.php.net/74478

Changed paths:
  M  NEWS
  M  ext/spl/spl_fixedarray.c
  A  ext/spl/tests/bug74478.phpt


Diff:
diff --git a/NEWS b/NEWS
index 1637b81..daab8dc 100644
--- 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
 
diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c
index 87c5926..4426bb6 100644
--- a/ext/spl/spl_fixedarray.c
+++ b/ext/spl/spl_fixedarray.c
@@ -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
index 0000000..da63984
--- /dev/null
+++ b/ext/spl/tests/bug74478.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Bug #74478: null coalescing operator failing with SplFixedArray
+--FILE--
+<?php
+
+class MyFixedArray extends \SplFixedArray
+{
+    public function offsetExists($name) {
+        echo "offsetExists($name)\n";
+        return parent::offsetExists($name);
+    }
+    public function offsetGet($name) {
+        echo "offsetGet($name)\n";
+        return parent::offsetGet($name);
+    }
+    public function offsetSet($name, $value) {
+        echo "offsetSet($name)\n";
+        return parent::offsetSet($name, $value);
+    }
+    public function offsetUnset($name) {
+        echo "offsetUnset($name)\n";
+        return parent::offsetUnset($name);
+    }
+
+};
+
+$fixedData = new MyFixedArray(10);
+var_dump(isset($fixedData[0][1][2]));
+var_dump(isset($fixedData[0]->foo));
+var_dump($fixedData[0] ?? 42);
+var_dump($fixedData[0][1][2] ?? 42);
+
+$fixedData[0] = new MyFixedArray(10);
+$fixedData[0][1] = new MyFixedArray(10);
+var_dump(isset($fixedData[0][1][2]));
+var_dump($fixedData[0][1][2] ?? 42);
+
+?>
+--EXPECT--
+offsetExists(0)
+bool(false)
+offsetExists(0)
+bool(false)
+offsetExists(0)
+int(42)
+offsetExists(0)
+int(42)
+offsetSet(0)
+offsetGet(0)
+offsetSet(1)
+offsetExists(0)
+offsetGet(0)
+offsetExists(1)
+offsetGet(1)
+offsetExists(2)
+bool(false)
+offsetExists(0)
+offsetGet(0)
+offsetExists(1)
+offsetGet(1)
+offsetExists(2)
+int(42)
\ No newline at end of file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.