On Fri, 2008-10-24 at 10:05 -0700, Stanislav Malyshev wrote:
> Hi!
>
> > nope that would mean that some scripts might work different between 5.2
> > and 5.3, now one gets an error. consider such a script:
>
> Just so it is clear - some scripts ALREADY work differently, that's why
> it says "BC break".
There's a difference between "working differently, but doing something"
and "throwing an error".
> > <?php
> > class Foo extends ArrayAccess {
> > public $prop = 42;
> > function offsetGet($n) { ... }
> > ....
> > }
> >
> > $o = new foo;
> > array_key_Exists('prop', $o);
> > ?>
> >
> > In <= 5.2 it will return the value of $o->prop, in 5.3 it would call the
> > offsetGet() method.
>
> In 5.2 it would return true and not the value of $o->prop.
> In 5.3 I don't think it would call offsetGet. It would call
> get_properties method of ArrayAccess, and that should return list of
> object's properties as array, so in this case the return will still be true.
I didn't check array_key_exists but most of the affected functions use
Z_OBJ_HT and therefore directly access the property table, not the
property access APIs.
Now changing to these APIs will be a silent change, whereas the old
behavior might be considered as a bug, throwing an error might be a good
compromise.
Example showing the 3 different behaviors:
$ cat array_key_exists_array_access.php
<?php
class Test implements ArrayAccess {
public $prop = "property";
public function offsetExists($key) {
echo __METHOD__,"($key)\n";
return false;
}
public function offsetGet($key) {
echo __METHOD__,"($key)\n";
return null;
}
public function offsetSet($key, $value) {}
public function offsetUnset($key) {}
}
$o = new Test();
var_dump(array_key_exists("prop", $o));
?>
1)
$ php52 array_key_exists_array_access.php
bool(true)
2)
$ php53 array_key_exists_array_access.php
Warning: array_key_exists() expects parameter 2 to be array, object
given in /home/johannes/public_html/- on line 20
NULL
3)
Result after using ArrayAccess:
Test::offsetExistst(prop)
bool(false)
Going from 1) to 3) will certainly confuse users and leads to changes in
behavior which can't be found in an easy way...
johannes
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php