Re: ArrayAccess::offsetGet not returning a ref

From: Date: Fri, 06 Aug 2010 14:50:33 +0000
Subject: Re: ArrayAccess::offsetGet not returning a ref
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-49216@lists.php.net to get a copy of this message
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?
> 
> 



Thread (12 messages)

« previous php.internals (#49216) next »