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:
Drew Paroski
2013-05-14 22:09:27 -07:00
commit de Sara Golemon
commit 16a372962c
4 arquivos alterados com 26 adições e 6 exclusões
+1 -1
Ver Arquivo
@@ -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;
}
+1 -1
Ver Arquivo
@@ -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(); \
+14 -3
Ver Arquivo
@@ -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;
}
+10 -1
Ver Arquivo
@@ -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