diff options
Diffstat (limited to 'ext/reflection/tests')
25 files changed, 506 insertions, 108 deletions
diff --git a/ext/reflection/tests/ReflectionClassConstant_basic1.phpt b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt index 548d64e1bf..78510d0b35 100644 --- a/ext/reflection/tests/ReflectionClassConstant_basic1.phpt +++ b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt @@ -73,7 +73,7 @@ bool(false) isProtected(): bool(false) getModifiers(): -int(256) +int(1) getDeclaringClass(): object(ReflectionClass)#3 (1) { ["name"]=> @@ -107,7 +107,7 @@ bool(false) isProtected(): bool(true) getModifiers(): -int(512) +int(2) getDeclaringClass(): object(ReflectionClass)#3 (1) { ["name"]=> @@ -141,7 +141,7 @@ bool(true) isProtected(): bool(false) getModifiers(): -int(1024) +int(4) getDeclaringClass(): object(ReflectionClass)#3 (1) { ["name"]=> @@ -175,7 +175,7 @@ bool(true) isProtected(): bool(false) getModifiers(): -int(1024) +int(4) getDeclaringClass(): object(ReflectionClass)#3 (1) { ["name"]=> diff --git a/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt index d99cd2561c..998bd4bea6 100644 --- a/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt +++ b/ext/reflection/tests/ReflectionClass_getInterfaces_002.phpt @@ -25,24 +25,24 @@ Array [name] => I6 ) - [I2] => ReflectionClass Object + [I4] => ReflectionClass Object ( - [name] => I2 + [name] => I4 ) - [I1] => ReflectionClass Object + [I3] => ReflectionClass Object ( - [name] => I1 + [name] => I3 ) - [I4] => ReflectionClass Object + [I2] => ReflectionClass Object ( - [name] => I4 + [name] => I2 ) - [I3] => ReflectionClass Object + [I1] => ReflectionClass Object ( - [name] => I3 + [name] => I1 ) [I5] => ReflectionClass Object diff --git a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt index 885bd908f1..b08fcaa4d4 100644 --- a/ext/reflection/tests/ReflectionClass_getMethods_003.phpt +++ b/ext/reflection/tests/ReflectionClass_getMethods_003.phpt @@ -17,9 +17,9 @@ class C { } $rc = new ReflectionClass("C"); -$StaticFlag = 0x01; -$pubFlag = 0x100; -$privFlag = 0x400; +$StaticFlag = ReflectionMethod::IS_STATIC; +$pubFlag = ReflectionMethod::IS_PUBLIC; +$privFlag = ReflectionMethod::IS_PRIVATE; echo "No methods:"; var_dump($rc->getMethods(0)); diff --git a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt index f77bbacda7..ffe8876133 100644 --- a/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionClass_getModifiers_basic.phpt @@ -29,8 +29,8 @@ dump_modifiers('g'); ?> --EXPECT-- int(0) +int(64) int(32) -int(4) int(0) int(0) int(0) diff --git a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt index d4a00f05fe..fe3792a30f 100644 --- a/ext/reflection/tests/ReflectionClass_getProperties_003.phpt +++ b/ext/reflection/tests/ReflectionClass_getProperties_003.phpt @@ -17,9 +17,9 @@ class C { } $rc = new ReflectionClass("C"); -$StaticFlag = 0x01; -$pubFlag = 0x100; -$privFlag = 0x400; +$StaticFlag = ReflectionProperty::IS_STATIC; +$pubFlag = ReflectionProperty::IS_PUBLIC; +$privFlag = ReflectionProperty::IS_PRIVATE; echo "No properties:"; var_dump($rc->getProperties(0)); diff --git a/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt b/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt new file mode 100644 index 0000000000..8671c2500b --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isSubclassOf_error2.phpt @@ -0,0 +1,35 @@ +--TEST-- +ReflectionClass::isSubclassOf() - fixed crash for unbound anonymous class +--FILE-- +<?php +class X { + public static function main() { + return new class() extends Base {}; + } +} +class Base {} +$check = function () { + $base = Base::class; + foreach (get_declared_classes() as $class) { + if (strpos($class, 'class@anonymous') === false) { + continue; + } + echo "Checking for $class\n"; + flush(); + $rc = new ReflectionClass($class); + var_export($rc->isSubclassOf($base)); + echo "\n"; + } +}; +// Should not show up in get_declared_classes until the anonymous class is bound. +$check(); +echo "After first check\n"; +X::main(); +$check(); +echo "Done\n"; +?> +--EXPECTF-- +After first check +Checking for class@%s +true +Done diff --git a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt index d82519e4f4..1370228f04 100644 --- a/ext/reflection/tests/ReflectionClass_modifiers_001.phpt +++ b/ext/reflection/tests/ReflectionClass_modifiers_001.phpt @@ -25,7 +25,7 @@ foreach ($classes as $class) { bool(false) bool(false) bool(true) -int(32) +int(64) bool(false) bool(false) bool(false) @@ -37,7 +37,7 @@ int(0) bool(true) bool(false) bool(false) -int(4) +int(32) bool(false) bool(true) bool(false) diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt index 14e8382e41..fb472681ca 100644 --- a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_002.phpt @@ -1,5 +1,5 @@ --TEST-- -ReflectionClass::getStaticPropertyValue() - bad params +ReflectionClass::setStaticPropertyValue() - bad params --CREDITS-- Robin Fernandes <robinf@php.net> Steve Seear <stevseea@php.net> diff --git a/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_003.phpt b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_003.phpt new file mode 100644 index 0000000000..a83900a123 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_setStaticPropertyValue_003.phpt @@ -0,0 +1,39 @@ +--TEST-- +ReflectionClass::setStaticPropertyValue() - type constraints must be enforced +--FILE-- +<?php + +class Test { + public static $x; + public static int $y = 2; +} + +$rc = new ReflectionClass('Test'); + +try { + $rc->setStaticPropertyValue("y", "foo"); +} catch (TypeError $e) { echo $e->getMessage(), "\n"; } +var_dump(Test::$y); + +$rc->setStaticPropertyValue("y", "21"); +var_dump(Test::$y); + + +Test::$x =& Test::$y; + +try { + $rc->setStaticPropertyValue("x", "foo"); +} catch (TypeError $e) { echo $e->getMessage(), "\n"; } +var_dump(Test::$y); + +$rc->setStaticPropertyValue("x", "42"); +var_dump(Test::$y); + +?> +--EXPECT-- +Typed property Test::$y must be int, string used +int(2) +int(21) +Cannot assign string to reference held by property Test::$y of type int +int(21) +int(42) diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index cafdd2e37c..e97af14110 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -13,8 +13,8 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { - Constants [3] { Constant [ public int IS_IMPLICIT_ABSTRACT ] { 16 } - Constant [ public int IS_EXPLICIT_ABSTRACT ] { 32 } - Constant [ public int IS_FINAL ] { 4 } + Constant [ public int IS_EXPLICIT_ABSTRACT ] { 64 } + Constant [ public int IS_FINAL ] { 32 } } - Static properties [0] { diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index 9b2122d1b9..5877f88e27 100644 --- a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt @@ -9,7 +9,7 @@ var_dump($ext->getClasses()); ?> ==DONE== --EXPECT-- -array(16) { +array(17) { ["ReflectionException"]=> object(ReflectionClass)#2 (1) { ["name"]=> @@ -90,5 +90,10 @@ array(16) { ["name"]=> string(23) "ReflectionZendExtension" } + ["ReflectionReference"]=> + object(ReflectionClass)#18 (1) { + ["name"]=> + string(19) "ReflectionReference" + } } ==DONE== diff --git a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt index 55aea10763..d1a19c7116 100644 --- a/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_getModifiers_basic.phpt @@ -87,151 +87,151 @@ printf("0x%08x\n", $a->getModifiers()); ?> --EXPECTF-- Modifiers for method TestClass::foo(): -0x00000100 +0x00000001 Modifiers for method TestClass::stat(): -0x00000101 +0x00000011 Modifiers for method TestClass::priv(): -0x00000400 +0x00000004 Modifiers for method TestClass::prot(): -0x00000200 +0x00000002 Modifiers for method TestClass::fin(): -0x00000104 +0x00000021 Modifiers for method TestClass::__destruct(): -0x00000100 +0x00000001 Modifiers for method TestClass::__call(): -0x00000100 +0x00000001 Modifiers for method TestClass::__clone(): -0x00000100 +0x00000001 Modifiers for method TestClass::__get(): -0x00000100 +0x00000001 Modifiers for method TestClass::__set(): -0x00000100 +0x00000001 Modifiers for method TestClass::__unset(): -0x00000100 +0x00000001 Modifiers for method TestClass::__isset(): -0x00000100 +0x00000001 Modifiers for method TestClass::__tostring(): -0x00000100 +0x00000001 Modifiers for method TestClass::__sleep(): -0x00000100 +0x00000001 Modifiers for method TestClass::__wakeup(): -0x00000100 +0x00000001 Modifiers for method TestClass::__set_state(): -0x00000100 +0x00000001 Modifiers for method TestClass::__autoload(): -0x00000100 +0x00000001 Modifiers for method TestClass::foo(): -0x00000100 +0x00000001 Modifiers for method TestClass::stat(): -0x00000101 +0x00000011 Modifiers for method TestClass::priv(): -0x00000400 +0x00000004 Modifiers for method TestClass::prot(): -0x00000200 +0x00000002 Modifiers for method TestClass::fin(): -0x00000104 +0x00000021 Modifiers for method TestClass::__destruct(): -0x00000100 +0x00000001 Modifiers for method TestClass::__call(): -0x00000100 +0x00000001 Modifiers for method TestClass::__clone(): -0x00000100 +0x00000001 Modifiers for method TestClass::__get(): -0x00000100 +0x00000001 Modifiers for method TestClass::__set(): -0x00000100 +0x00000001 Modifiers for method TestClass::__unset(): -0x00000100 +0x00000001 Modifiers for method TestClass::__isset(): -0x00000100 +0x00000001 Modifiers for method TestClass::__tostring(): -0x00000100 +0x00000001 Modifiers for method TestClass::__sleep(): -0x00000100 +0x00000001 Modifiers for method TestClass::__wakeup(): -0x00000100 +0x00000001 Modifiers for method TestClass::__set_state(): -0x00000100 +0x00000001 Modifiers for method TestClass::__autoload(): -0x00000100 +0x00000001 Modifiers for method TestInterface::int(): -0x00000102 +0x00000041 Modifiers for method TestInterface::__clone(): -0x00000102 +0x00000041 Modifiers for method AbstractClass::foo(): -0x00000102 +0x00000041 Wrong number of params: @@ -239,4 +239,4 @@ Wrong number of params: Warning: ReflectionMethod::getModifiers() expects exactly 0 parameters, 1 given in %s on line %d ReflectionMethod::getModifiers() modifiers: -0x00000100 +0x00000001 diff --git a/ext/reflection/tests/ReflectionProperty_basic2.phpt b/ext/reflection/tests/ReflectionProperty_basic2.phpt index 0491073ace..09495f744b 100644 --- a/ext/reflection/tests/ReflectionProperty_basic2.phpt +++ b/ext/reflection/tests/ReflectionProperty_basic2.phpt @@ -43,7 +43,7 @@ Reflecting on property TestClass::pub isDefault(): bool(true) getModifiers(): -int(256) +int(1) getDeclaringClass(): object(ReflectionClass)#%d (1) { ["name"]=> @@ -59,7 +59,7 @@ Reflecting on property TestClass::stat isDefault(): bool(true) getModifiers(): -int(257) +int(17) getDeclaringClass(): object(ReflectionClass)#%d (1) { ["name"]=> @@ -75,7 +75,7 @@ Reflecting on property TestClass::prot isDefault(): bool(true) getModifiers(): -int(512) +int(2) getDeclaringClass(): object(ReflectionClass)#%d (1) { ["name"]=> @@ -93,7 +93,7 @@ Reflecting on property TestClass::priv isDefault(): bool(true) getModifiers(): -int(1024) +int(4) getDeclaringClass(): object(ReflectionClass)#%d (1) { ["name"]=> diff --git a/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt index 6d7ddbe834..a297a10436 100644 --- a/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt +++ b/ext/reflection/tests/ReflectionProperty_getModifiers.001.phpt @@ -40,27 +40,27 @@ reflectProperty("TestClass", "priv"); Reflecting on property TestClass::pub getModifiers(): -int(256) +int(1) ********************************** ********************************** Reflecting on property TestClass::stat getModifiers(): -int(257) +int(17) ********************************** ********************************** Reflecting on property TestClass::prot getModifiers(): -int(512) +int(2) ********************************** ********************************** Reflecting on property TestClass::priv getModifiers(): -int(1024) +int(4) ********************************** diff --git a/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt b/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt index 4c99444e30..6856569d3e 100644 --- a/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt +++ b/ext/reflection/tests/ReflectionProperty_getModifiers_basic.phpt @@ -32,15 +32,15 @@ for ($i = 1;$i <= 6;$i++) { ?> --EXPECT-- -C::a1: int(256) -D::a1: int(256) -C::a2: int(512) -D::a2: int(512) -C::a3: int(1024) -D::a3: int(1024) -C::a4: int(257) -D::a4: int(257) -C::a5: int(513) -D::a5: int(513) -C::a6: int(1025) -D::a6: int(1025) +C::a1: int(1) +D::a1: int(1) +C::a2: int(2) +D::a2: int(2) +C::a3: int(4) +D::a3: int(4) +C::a4: int(17) +D::a4: int(17) +C::a5: int(18) +D::a5: int(18) +C::a6: int(20) +D::a6: int(20) diff --git a/ext/reflection/tests/ReflectionProperty_isInitialized.phpt b/ext/reflection/tests/ReflectionProperty_isInitialized.phpt new file mode 100644 index 0000000000..f1f6e53ebd --- /dev/null +++ b/ext/reflection/tests/ReflectionProperty_isInitialized.phpt @@ -0,0 +1,113 @@ +--TEST-- +Test ReflectionProperty::isInitialized() +--FILE-- +<?php + +class A { + public static ?string $ssv = null; + public static ?string $ss; + public static $s; + public ?int $iv = null; + public ?int $i; + public $n; + + private int $p; +} + +class B extends A { } + +echo "Static properties:\n"; +var_dump((new ReflectionProperty(A::class, 'ssv'))->isInitialized()); +var_dump((new ReflectionProperty(A::class, 'ss'))->isInitialized()); +var_dump((new ReflectionProperty(A::class, 's'))->isInitialized()); + +echo "Declared properties:\n"; +$a = new A; +var_dump((new ReflectionProperty($a, 'iv'))->isInitialized($a)); +var_dump((new ReflectionProperty($a, 'i'))->isInitialized($a)); +var_dump((new ReflectionProperty($a, 'n'))->isInitialized($a)); + +echo "Declared properties after unset:\n"; +unset($a->iv); +unset($a->i); +unset($a->n); +var_dump((new ReflectionProperty($a, 'i'))->isInitialized($a)); +var_dump((new ReflectionProperty($a, 'iv'))->isInitialized($a)); +var_dump((new ReflectionProperty($a, 'n'))->isInitialized($a)); + +echo "Dynamic properties:\n"; +$a->d = null; +$rp = new ReflectionProperty($a, 'd'); +var_dump($rp->isInitialized($a)); +unset($a->d); +var_dump($rp->isInitialized($a)); + +echo "Visibility handling:\n"; +$rp = new ReflectionProperty('A', 'p'); +try { + var_dump($rp->isInitialized($a)); +} catch (ReflectionException $e) { + echo $e->getMessage(), "\n"; +} +$rp->setAccessible(true); +var_dump($rp->isInitialized($a)); + +echo "Object type:\n"; +$rp = new ReflectionProperty('B', 'i'); +var_dump($rp->isInitialized($a)); + +try { + var_dump($rp->isInitialized(new stdClass)); +} catch (ReflectionException $e) { + echo $e->getMessage(), "\n"; +} + +class WithMagic { + public $prop; + public int $intProp; + + public function __isset($name) { + echo "__isset($name)\n"; + return true; + } + + public function __get($name) { + echo "__get($name)\n"; + return "foobar"; + } +} + +echo "Class with __isset:\n"; +$obj = new WithMagic; +unset($obj->prop); +$rp = new ReflectionProperty('WithMagic', 'prop'); +var_dump($rp->isInitialized($obj)); +$rp = new ReflectionProperty('WithMagic', 'intProp'); +var_dump($rp->isInitialized($obj)); + +?> +--EXPECT-- +Static properties: +bool(true) +bool(false) +bool(true) +Declared properties: +bool(true) +bool(false) +bool(true) +Declared properties after unset: +bool(false) +bool(false) +bool(false) +Dynamic properties: +bool(true) +bool(false) +Visibility handling: +Cannot access non-public member A::$p +bool(false) +Object type: +bool(false) +Given object is not an instance of the class this property was declared in +Class with __isset: +bool(false) +bool(false) diff --git a/ext/reflection/tests/ReflectionProperty_typed_static.phpt b/ext/reflection/tests/ReflectionProperty_typed_static.phpt new file mode 100644 index 0000000000..77f95d77ef --- /dev/null +++ b/ext/reflection/tests/ReflectionProperty_typed_static.phpt @@ -0,0 +1,51 @@ +--TEST-- +ReflectionProperty::getValue() on typed static property +--FILE-- +<?php + +class Test { + public static int $x = 42; + public static int $y; + public static $z; +} + +$rp = new ReflectionProperty('Test', 'x'); +var_dump($rp->getValue()); + +$rp = new ReflectionProperty('Test', 'y'); +try { + var_dump($rp->getValue()); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +$rp->setValue("24"); +var_dump($rp->getValue()); + +try { + $rp->setValue("foo"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +var_dump($rp->getValue()); + +Test::$z =& Test::$y; + +$rp = new ReflectionProperty('Test', 'z'); +try { + $rp->setValue("foo"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} +var_dump($rp->getValue()); + + +?> +--EXPECT-- +int(42) +Typed static property Test::$y must not be accessed before initialization +int(24) +Typed property Test::$y must be int, string used +int(24) +Cannot assign string to reference held by property Test::$y of type int +int(24) diff --git a/ext/reflection/tests/ReflectionReference.phpt b/ext/reflection/tests/ReflectionReference.phpt new file mode 100644 index 0000000000..76d2512123 --- /dev/null +++ b/ext/reflection/tests/ReflectionReference.phpt @@ -0,0 +1,55 @@ +--TEST-- +Basic ReflectionReference functionality +--FILE-- +<?php + +$ary = [0, 1, 2]; +$ref1 =& $ary[1]; +unset($ref1); +$ref2 =& $ary[2]; + +echo "fromArrayElement():\n"; +$r0 = ReflectionReference::fromArrayElement($ary, 0); +var_dump($r0 === null); +$r1 = ReflectionReference::fromArrayElement($ary, 1); +var_dump($r1 instanceof ReflectionReference); +$r2 = ReflectionReference::fromArrayElement($ary, 2); +var_dump($r2 instanceof ReflectionReference); + +echo "getId() #1:\n"; +var_dump($r1->getId() === $r1->getId()); +var_dump($r2->getId() === $r2->getId()); +var_dump($r1->getId() !== $r2->getId()); + +echo "getId() #2:\n"; +$ary2 = [&$ary[1], &$ref2]; +$r1_2 = ReflectionReference::fromArrayElement($ary2, 0); +$r2_2 = ReflectionReference::fromArrayElement($ary2, 1); +var_dump($r1->getId() === $r1_2->getId()); +var_dump($r2->getId() === $r2_2->getId()); + +echo "getId() #3:\n"; +$r1_id = $r1->getId(); +$r2_id = $r2->getId(); +unset($r0, $r1, $r2, $r1_2, $r2_2); +$r1 = ReflectionReference::fromArrayElement($ary, 1); +$r2 = ReflectionReference::fromArrayElement($ary, 2); +var_dump($r1_id === $r1->getId()); +var_dump($r2_id === $r2->getId()); + +?> +--EXPECT-- +fromArrayElement(): +bool(true) +bool(true) +bool(true) +getId() #1: +bool(true) +bool(true) +bool(true) +getId() #2: +bool(true) +bool(true) +getId() #3: +bool(true) +bool(true) diff --git a/ext/reflection/tests/ReflectionReference_errors.phpt b/ext/reflection/tests/ReflectionReference_errors.phpt new file mode 100644 index 0000000000..8e52a1d223 --- /dev/null +++ b/ext/reflection/tests/ReflectionReference_errors.phpt @@ -0,0 +1,52 @@ +--TEST-- +Various error conditions for ReflectionReference +--FILE-- +<?php + +try { + new ReflectionReference(); +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +try { + ReflectionReference::fromArrayElement(new stdClass, "test"); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +try { + ReflectionReference::fromArrayElement([], 1.5); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} + +try { + $ary = [0, 1, 2]; + ReflectionReference::fromArrayElement($ary, 3); +} catch (ReflectionException $e) { + echo $e->getMessage(), "\n"; +} + +try { + $ary = [&$ary]; + $ref = ReflectionReference::fromArrayElement($ary, 0); + var_dump(serialize($ref)); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} + +var_dump(unserialize('O:19:"ReflectionReference":0:{}')); + +?> +--EXPECTF-- +Call to private ReflectionReference::__construct() from invalid context +ReflectionReference::fromArrayElement() expects parameter 1 to be array, object given +Key must be array or string +Array key not found +Serialization of 'ReflectionReference' is not allowed + +Warning: Erroneous data format for unserializing 'ReflectionReference' in %s on line %d + +Notice: unserialize(): Error at offset 30 of 31 bytes in %s on line %d +bool(false) diff --git a/ext/reflection/tests/ReflectionType_001.phpt b/ext/reflection/tests/ReflectionType_001.phpt index d949e18107..e47a9615ba 100644 --- a/ext/reflection/tests/ReflectionType_001.phpt +++ b/ext/reflection/tests/ReflectionType_001.phpt @@ -74,6 +74,32 @@ foreach ([ } } +echo "\n*** property types\n"; + +class PropTypeTest { + public int $int; + public string $string; + public array $arr; + public iterable $iterable; + public stdClass $std; + public OtherThing $other; + public $mixed; +} + +$reflector = new ReflectionClass(PropTypeTest::class); + +foreach ($reflector->getProperties() as $name => $property) { + if ($property->hasType()) { + printf("public %s $%s;\n", + $property->getType(), $property->getName()); + } else printf("public $%s;\n", $property->getName()); +} + +echo "*** resolved property types\n"; +$obj = new PropTypeTest; +$obj->std = new stdClass; +$r = (new ReflectionProperty($obj, 'std'))->getType(); +var_dump($r->getName()); ?> --EXPECT-- *** functions @@ -185,3 +211,14 @@ bool(true) bool(false) bool(false) string(4) "Test" + +*** property types +public int $int; +public string $string; +public array $arr; +public iterable $iterable; +public stdClass $std; +public OtherThing $other; +public $mixed; +*** resolved property types +string(8) "stdClass" diff --git a/ext/reflection/tests/ReflectionZendExtension.phpt b/ext/reflection/tests/ReflectionZendExtension.phpt index b4cd96e97b..e11087cbf2 100644 --- a/ext/reflection/tests/ReflectionZendExtension.phpt +++ b/ext/reflection/tests/ReflectionZendExtension.phpt @@ -14,9 +14,9 @@ var_dump($reflection->getURL()); var_dump($reflection->getVersion() === PHP_VERSION); var_dump(gettype($reflection->export('Zend OPcache', true)) === 'string'); ?> ---EXPECTF-- +--EXPECT-- string(17) "Zend Technologies" -string(23) "Copyright (c) 1999-20%d" +string(13) "Copyright (c)" string(12) "Zend OPcache" string(20) "http://www.zend.com/" bool(true) diff --git a/ext/reflection/tests/bug49719.phpt b/ext/reflection/tests/bug49719.phpt index f55334c951..6211b6b543 100644 --- a/ext/reflection/tests/bug49719.phpt +++ b/ext/reflection/tests/bug49719.phpt @@ -36,7 +36,7 @@ $prop->setAccessible(true); var_dump($prop->getValue(new b2)); ?> ---EXPECTF-- +--EXPECT-- bool(false) bool(false) bool(false) diff --git a/ext/reflection/tests/bug61388.phpt b/ext/reflection/tests/bug61388.phpt index 3d6dc83fa0..b9fe6bfaaa 100644 --- a/ext/reflection/tests/bug61388.phpt +++ b/ext/reflection/tests/bug61388.phpt @@ -14,12 +14,6 @@ print_r($reflObj->getProperties(ReflectionProperty::IS_PUBLIC)); --EXPECT-- Array ( - [0] => ReflectionProperty Object - ( - [name] => test - [class] => ArrayObject - ) - ) Array ( diff --git a/ext/reflection/tests/bug76737.phpt b/ext/reflection/tests/bug76737.phpt new file mode 100644 index 0000000000..716b40e76a --- /dev/null +++ b/ext/reflection/tests/bug76737.phpt @@ -0,0 +1,33 @@ +--TEST-- +Bug #76737: Unserialized reflection objects are broken, they shouldn't be serializable +--FILE-- +<?php + +try { + $r = new ReflectionClass('stdClass'); + var_dump(serialize($r)); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + $s = 'C:15:"ReflectionClass":0:{}'; + var_dump(unserialize($s)); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} +try { + $s = 'O:15:"ReflectionClass":0:{}'; + var_dump(unserialize($s)); +} catch (Exception $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECTF-- +Serialization of 'ReflectionClass' is not allowed +Unserialization of 'ReflectionClass' is not allowed + +Warning: Erroneous data format for unserializing 'ReflectionClass' in %s on line %d + +Notice: unserialize(): Error at offset 26 of 27 bytes in %s on line %d +bool(false) diff --git a/ext/reflection/tests/exception.inc b/ext/reflection/tests/exception.inc deleted file mode 100644 index da3fceaac7..0000000000 --- a/ext/reflection/tests/exception.inc +++ /dev/null @@ -1,16 +0,0 @@ -<?php -class ReflectionExceptionEx extends ReflectionException { - function MyException($_errno, $_errmsg) { - $this->errno = $_errno; - $this->errmsg = $_errmsg; - } - - function getErrno() { - return $this->errno; - } - - function getErrmsg() { - return $this->errmsg; - } -} -?> |