From 105db96e781d5def2eeec102f9b5e56e187b78f1 Mon Sep 17 00:00:00 2001 From: Etienne Kneuss Date: Wed, 3 Nov 2010 15:40:24 +0000 Subject: [PATCH] Fixed covariance of return-by-ref constraints --- Zend/tests/objects_032.phpt | 40 +++++++++++++++++++++++++++++++++++++ Zend/zend_compile.c | 7 +++++-- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/objects_032.phpt diff --git a/Zend/tests/objects_032.phpt b/Zend/tests/objects_032.phpt new file mode 100644 index 00000000000..e5e3ecadb2e --- /dev/null +++ b/Zend/tests/objects_032.phpt @@ -0,0 +1,40 @@ +--TEST-- +Covariant return-by-ref constraints +--FILE-- +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== diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 08b70b22672..c49dce6fcb7 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -2956,8 +2956,9 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c 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 @@ static zend_bool zend_do_perform_implementation_check(const zend_function *fe, c /* 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; }