]> granicus.if.org Git - php/commitdiff
Fixed covariance of return-by-ref constraints
authorEtienne Kneuss <colder@php.net>
Wed, 3 Nov 2010 15:40:24 +0000 (15:40 +0000)
committerEtienne Kneuss <colder@php.net>
Wed, 3 Nov 2010 15:40:24 +0000 (15:40 +0000)
NEWS
Zend/tests/objects_032.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/NEWS b/NEWS
index 61307e58c8d91bdfa6cfa38ae47c70db5b5d9474..38ec9ea4f00007c29b58d147ceb3ae0c5f2df467 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -50,6 +50,7 @@
   large amount of data) (CVE-2010-3710). (Adam)
 - Fixed ReflectionProperty::isDefault() giving a wrong result for properties
   obtained with ReflectionClass::getProperties(). (Gustavo)
+- Fixed covariance of return-by-ref constraints. (Etienne)
 
 - Fixed bug #53198 (changing INI setting "from" with ini_set did not have any
   effect). (Gustavo)
diff --git a/Zend/tests/objects_032.phpt b/Zend/tests/objects_032.phpt
new file mode 100644 (file)
index 0000000..e5e3eca
--- /dev/null
@@ -0,0 +1,40 @@
+--TEST--
+Covariant return-by-ref constraints
+--FILE--
+<?php
+
+class A implements ArrayAccess {
+    public $foo = array();
+
+    public function &offsetGet($n) {
+        return $this->foo[$n];
+    }
+
+    public function offsetSet($n, $v) {
+    }
+    public function offsetUnset($n) {
+    }
+    public function offsetExists($n) {
+    }
+}
+
+$a = new A;
+
+$a['foo']['bar'] = 2;
+
+var_dump($a);
+
+?>
+==DONE==
+--EXPECTF--
+object(A)#1 (1) {
+  ["foo"]=>
+  array(1) {
+    ["foo"]=>
+    array(1) {
+      ["bar"]=>
+      int(2)
+    }
+  }
+}
+==DONE==
index febf2da905c1f009aec5d5f2dfa1ceed443199f6..799b77410b371583e3e6833d297efee720889c34 100644 (file)
@@ -2557,7 +2557,8 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
                return 0;
        }
 
-       if (fe->common.return_reference != proto->common.return_reference) {
+       /* by-ref constraints on return values are covariant */
+       if (proto->common.return_reference && !fe->common.return_reference) {
                return 0;
        }
 
@@ -2581,6 +2582,8 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c
                        /* Only one has an array type hint and the other one doesn't */
                        return 0;
                }
+
+               /* by-ref constraints on arguments are invariant */
                if (fe->common.arg_info[i].pass_by_reference != proto->common.arg_info[i].pass_by_reference) {
                        return 0;
                }