The attached patch is the suggested fix. I made this against master on github.

-ralph

Ralph Schindler wrote:
I can give 2 examples, one that triggers the problem, the other that is a real world issue:

---

Simple:

<?php

interface I {
    public function foo($name);
}

class C implements I {
    public function & foo($name) {}
}

$c = new Bar();


running this produces:

$ php -d error_reporting=32767 test-reference-in-signature.php
PHP Fatal error: Declaration of C::foo() must be compatible with that of I::foo() in path/to/test-reference-in-signature.php on line 8

----

Real world issue with ArrayAccess:


<?php

class SomeContainer implements ArrayAccess {
    protected $_data = array('foo' => array(1,2,3));
    public function & offsetGet($name) {
        $r = & $this->_data['foo'];
        return $r;
    }
    public function offsetSet($name, $value) {}
    public function offsetExists($name) {}
    public function offsetUnset($name) {}
}

$b = new Bar();
$b['foo'][3] = 4; // implies Bar::offsetGet() happens before assign


running this produces:

$ php -d error_reporting=32767 test-reference-in-arrayaccess.php
PHP Fatal error: Declaration of SomeContainer::offsetGet() must be compatible with that of ArrayAccess::offsetGet() in path/to/test-reference-in-arrayaccess.php on line 3


-ralph

Stas Malyshev wrote:
Hi!

I'd opt for option (d) for all prototype/signature checking. Here's why:

I think relaxing the check may make sense. Do you have some code example that doesn't work and you want it to work?



diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index 6a6b597..52decaa 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2932,10 +2932,6 @@ static zend_bool 
zend_do_perform_implementation_check(const zend_function *fe, c
                return 0;
        }
 
-       if (fe->common.return_reference != proto->common.return_reference) {
-               return 0;
-       }
-
        for (i=0; i < proto->common.num_args; i++) {
                if (ZEND_LOG_XOR(fe->common.arg_info[i].class_name, 
proto->common.arg_info[i].class_name)) {
                        /* Only one has a type hint and the other one doesn't */
-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to