colder Wed, 03 Nov 2010 15:40:24 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=305057
Log: Fixed covariance of return-by-ref constraints Changed paths: U php/php-src/branches/PHP_5_3/NEWS A php/php-src/branches/PHP_5_3/Zend/tests/objects_032.phpt U php/php-src/branches/PHP_5_3/Zend/zend_compile.c A php/php-src/trunk/Zend/tests/objects_032.phpt U php/php-src/trunk/Zend/zend_compile.c Modified: php/php-src/branches/PHP_5_3/NEWS =================================================================== --- php/php-src/branches/PHP_5_3/NEWS 2010-11-03 14:26:32 UTC (rev 305056) +++ php/php-src/branches/PHP_5_3/NEWS 2010-11-03 15:40:24 UTC (rev 305057) @@ -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) Added: php/php-src/branches/PHP_5_3/Zend/tests/objects_032.phpt =================================================================== --- php/php-src/branches/PHP_5_3/Zend/tests/objects_032.phpt (rev 0) +++ php/php-src/branches/PHP_5_3/Zend/tests/objects_032.phpt 2010-11-03 15:40:24 UTC (rev 305057) @@ -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== Modified: php/php-src/branches/PHP_5_3/Zend/zend_compile.c =================================================================== --- php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2010-11-03 14:26:32 UTC (rev 305056) +++ php/php-src/branches/PHP_5_3/Zend/zend_compile.c 2010-11-03 15:40:24 UTC (rev 305057) @@ -2557,7 +2557,8 @@ 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 @@ /* 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; } Added: php/php-src/trunk/Zend/tests/objects_032.phpt =================================================================== --- php/php-src/trunk/Zend/tests/objects_032.phpt (rev 0) +++ php/php-src/trunk/Zend/tests/objects_032.phpt 2010-11-03 15:40:24 UTC (rev 305057) @@ -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== Modified: php/php-src/trunk/Zend/zend_compile.c =================================================================== --- php/php-src/trunk/Zend/zend_compile.c 2010-11-03 14:26:32 UTC (rev 305056) +++ php/php-src/trunk/Zend/zend_compile.c 2010-11-03 15:40:24 UTC (rev 305057) @@ -2956,8 +2956,9 @@ return 0; } - if ((fe->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) != - (proto->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)) { + /* by-ref constraints on return values are covariant */ + if ((proto->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) + && !(fe->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)) { return 0; } @@ -2981,6 +2982,8 @@ /* Incompatible type hint */ 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; }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php