Tolerate "isset($c->prop)" for collections
Currently collections define magic __get, __set, __isset, and __unset methods which will throw exceptions if any property access is attempted on collections (such as "isset($vec->prop)" and "$x = $vec->prop"). However, there is existing code that uses isset() to check if various objects have a property with a certain name, and it feels like throwing an exception here is a little harsh. This diff updates collections to be tolerant of reading properties.
Esse commit está contido em:
@@ -453,7 +453,7 @@ void throw_collection_modified() {
|
||||
|
||||
void throw_collection_property_exception() {
|
||||
Object e(SystemLib::AllocInvalidOperationExceptionObject(
|
||||
"Cannot access property on a collection"));
|
||||
"Cannot access a property on a collection"));
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
@@ -4567,7 +4567,7 @@ void c_PairIterator::t_rewind() {
|
||||
throw_collection_property_exception(); \
|
||||
} \
|
||||
bool c_##cls::t___isset(Variant name) { \
|
||||
throw_collection_property_exception(); \
|
||||
return false; \
|
||||
} \
|
||||
Variant c_##cls::t___unset(Variant name) { \
|
||||
throw_collection_property_exception(); \
|
||||
|
||||
@@ -8,14 +8,25 @@ try {
|
||||
$obj = new $cls;
|
||||
try {
|
||||
$x = $obj->foo;
|
||||
echo "get: ";
|
||||
var_dump($x);
|
||||
} catch (RuntimeException $e) {
|
||||
echo $i;
|
||||
echo "get throws, i = ";
|
||||
var_dump($i);
|
||||
}
|
||||
try {
|
||||
$x = isset($obj->foo);
|
||||
echo "isset: ";
|
||||
var_dump($x);
|
||||
} catch (RuntimeException $e) {
|
||||
echo "isset throws, i = ";
|
||||
var_dump($i);
|
||||
}
|
||||
++$i;
|
||||
try {
|
||||
$obj->foo = 123;
|
||||
} catch (RuntimeException $e) {
|
||||
echo $i;
|
||||
echo "set throws, i = ";
|
||||
var_dump($i);
|
||||
}
|
||||
++$i;
|
||||
}
|
||||
|
||||
@@ -1 +1,10 @@
|
||||
012345Done
|
||||
get throws, i = int(0)
|
||||
isset: bool(false)
|
||||
set throws, i = int(0)
|
||||
get throws, i = int(1)
|
||||
isset: bool(false)
|
||||
set throws, i = int(1)
|
||||
get throws, i = int(2)
|
||||
isset: bool(false)
|
||||
set throws, i = int(2)
|
||||
Done
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário