diff options
Diffstat (limited to 'ext/reflection/tests')
27 files changed, 507 insertions, 168 deletions
diff --git a/ext/reflection/tests/004.phpt b/ext/reflection/tests/004.phpt index 41632aa3ba..36ae406b43 100644 --- a/ext/reflection/tests/004.phpt +++ b/ext/reflection/tests/004.phpt @@ -38,6 +38,6 @@ try { echo "===DONE===\n";?> --EXPECTF-- Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; a has a deprecated constructor in %s on line %d -Non-object passed to Invoke() +Trying to invoke non static method a::a() without an object Given object is not an instance of the class this method was declared in ===DONE=== diff --git a/ext/reflection/tests/007.phpt b/ext/reflection/tests/007.phpt index 004158ccff..d9204171b5 100644 --- a/ext/reflection/tests/007.phpt +++ b/ext/reflection/tests/007.phpt @@ -25,6 +25,10 @@ function test($class) { var_dump($e->getMessage()); } + catch (Throwable $e) + { + echo "Exception: " . $e->getMessage() . "\n"; + } echo "====>newInstance(25)\n"; try @@ -129,15 +133,7 @@ object(WithCtor)#%d (0) { ====>WithCtorWithArgs ====>newInstance() - -Warning: Missing argument 1 for WithCtorWithArgs::__construct() in %s007.php on line %d - -Notice: Undefined variable: arg in %s007.php on line %d -WithCtorWithArgs::__construct() -array(0) { -} -object(WithCtorWithArgs)#%d (0) { -} +Exception: Too few arguments to function WithCtorWithArgs::__construct(), 0 passed and exactly 1 expected ====>newInstance(25) WithCtorWithArgs::__construct(25) array(1) { diff --git a/ext/reflection/tests/017.phpt b/ext/reflection/tests/017.phpt index d40c4d83f9..1d9275d21b 100644 --- a/ext/reflection/tests/017.phpt +++ b/ext/reflection/tests/017.phpt @@ -10,12 +10,12 @@ class Foo { $class = new ReflectionClass("Foo"); echo $class; ?> ---EXPECTF-- +--EXPECTF-- Class [ <user> class Foo ] { @@ %s017.php 2-4 - Constants [1] { - Constant [ string test ] { ok } + Constant [ public string test ] { ok } } - Static properties [0] { diff --git a/ext/reflection/tests/ReflectionClassConstant_basic1.phpt b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt new file mode 100644 index 0000000000..fd8118650f --- /dev/null +++ b/ext/reflection/tests/ReflectionClassConstant_basic1.phpt @@ -0,0 +1,194 @@ +--TEST-- +Test usage of ReflectionClassConstant methods __toString(), export(), getName(), getValue(), isPublic(), isPrivate(), isProtected(), getModifiers(), getDeclaringClass() and getDocComment(). +--FILE-- +<?php + +function reflectClassConstant($base, $constant) { + $constInfo = new ReflectionClassConstant($base, $constant); + echo "**********************************\n"; + $class = is_object($base) ? get_class($base) : $base; + echo "Reflecting on class constant $class::$constant\n\n"; + echo "__toString():\n"; + var_dump($constInfo->__toString()); + echo "export():\n"; + var_dump(ReflectionClassConstant::export($base, $constant, true)); + echo "export():\n"; + var_dump(ReflectionClassConstant::export($base, $constant, false)); + echo "getName():\n"; + var_dump($constInfo->getName()); + echo "getValue():\n"; + var_dump($constInfo->getValue()); + echo "isPublic():\n"; + var_dump($constInfo->isPublic()); + echo "isPrivate():\n"; + var_dump($constInfo->isPrivate()); + echo "isProtected():\n"; + var_dump($constInfo->isProtected()); + echo "getModifiers():\n"; + var_dump($constInfo->getModifiers()); + echo "getDeclaringClass():\n"; + var_dump($constInfo->getDeclaringClass()); + echo "getDocComment():\n"; + var_dump($constInfo->getDocComment()); + echo "\n**********************************\n"; +} + +class TestClass { + public const /** My Doc comment */ PUB = true; + /** Another doc comment */ + protected const PROT = 4; + private const PRIV = "keepOut"; +} +$instance = new TestClass(); + +reflectClassConstant("TestClass", "PUB"); +reflectClassConstant("TestClass", "PROT"); +reflectClassConstant("TestClass", "PRIV"); +reflectClassConstant($instance, "PRIV"); +reflectClassConstant($instance, "BAD_CONST"); + +?> +--EXPECTF-- +********************************** +Reflecting on class constant TestClass::PUB + +__toString(): +string(38) "Constant [ public boolean PUB ] { 1 } +" +export(): +string(38) "Constant [ public boolean PUB ] { 1 } +" +export(): +Constant [ public boolean PUB ] { 1 } + +NULL +getName(): +string(3) "PUB" +getValue(): +bool(true) +isPublic(): +bool(true) +isPrivate(): +bool(false) +isProtected(): +bool(false) +getModifiers(): +int(256) +getDeclaringClass(): +object(ReflectionClass)#3 (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +string(21) "/** My Doc comment */" + +********************************** +********************************** +Reflecting on class constant TestClass::PROT + +__toString(): +string(42) "Constant [ protected integer PROT ] { 4 } +" +export(): +string(42) "Constant [ protected integer PROT ] { 4 } +" +export(): +Constant [ protected integer PROT ] { 4 } + +NULL +getName(): +string(4) "PROT" +getValue(): +int(4) +isPublic(): +bool(false) +isPrivate(): +bool(false) +isProtected(): +bool(true) +getModifiers(): +int(512) +getDeclaringClass(): +object(ReflectionClass)#3 (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +string(26) "/** Another doc comment */" + +********************************** +********************************** +Reflecting on class constant TestClass::PRIV + +__toString(): +string(45) "Constant [ private string PRIV ] { keepOut } +" +export(): +string(45) "Constant [ private string PRIV ] { keepOut } +" +export(): +Constant [ private string PRIV ] { keepOut } + +NULL +getName(): +string(4) "PRIV" +getValue(): +string(7) "keepOut" +isPublic(): +bool(false) +isPrivate(): +bool(true) +isProtected(): +bool(false) +getModifiers(): +int(1024) +getDeclaringClass(): +object(ReflectionClass)#3 (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +bool(false) + +********************************** +********************************** +Reflecting on class constant TestClass::PRIV + +__toString(): +string(45) "Constant [ private string PRIV ] { keepOut } +" +export(): +string(45) "Constant [ private string PRIV ] { keepOut } +" +export(): +Constant [ private string PRIV ] { keepOut } + +NULL +getName(): +string(4) "PRIV" +getValue(): +string(7) "keepOut" +isPublic(): +bool(false) +isPrivate(): +bool(true) +isProtected(): +bool(false) +getModifiers(): +int(1024) +getDeclaringClass(): +object(ReflectionClass)#3 (1) { + ["name"]=> + string(9) "TestClass" +} +getDocComment(): +bool(false) + +********************************** + +Fatal error: Uncaught ReflectionException: Class Constant TestClass::BAD_CONST does not exist in %s:%d +Stack trace: +#0 %s(%d): ReflectionClassConstant->__construct(Object(TestClass), 'BAD_CONST') +#1 %s(%d): reflectClassConstant(Object(TestClass), 'BAD_CONST') +#2 {main} + thrown in %s on line %d diff --git a/ext/reflection/tests/ReflectionClassConstant_getValue.phpt b/ext/reflection/tests/ReflectionClassConstant_getValue.phpt new file mode 100644 index 0000000000..e447d15357 --- /dev/null +++ b/ext/reflection/tests/ReflectionClassConstant_getValue.phpt @@ -0,0 +1,47 @@ +--TEST-- +Test variations of getting constant values +--FILE-- +<?php + +/* Use separate classes to make sure that in-place constant updates don't interfere */ +class A { + const X = self::Y * 2; + const Y = 1; +} +class B { + const X = self::Y * 2; + const Y = 1; +} +class C { + const X = self::Y * 2; + const Y = 1; +} + +var_dump((new ReflectionClassConstant('A', 'X'))->getValue()); +echo new ReflectionClassConstant('B', 'X'); +echo new ReflectionClass('C'); + +?> +--EXPECTF-- +int(2) +Constant [ public integer X ] { 2 } +Class [ <user> class C ] { + @@ %s 12-15 + + - Constants [2] { + Constant [ public integer X ] { 2 } + Constant [ public integer Y ] { 1 } + } + + - Static properties [0] { + } + + - Static methods [0] { + } + + - Properties [0] { + } + + - Methods [0] { + } +} diff --git a/ext/reflection/tests/ReflectionClass_export_array_bug72222.phpt b/ext/reflection/tests/ReflectionClass_export_array_bug72222.phpt index e64dc97109..9ccc285433 100644 --- a/ext/reflection/tests/ReflectionClass_export_array_bug72222.phpt +++ b/ext/reflection/tests/ReflectionClass_export_array_bug72222.phpt @@ -13,8 +13,8 @@ Class [ <user> class A ] { @@ %s 2-5 - Constants [2] { - Constant [ integer A ] { 8 } - Constant [ array B ] { Array } + Constant [ public integer A ] { 8 } + Constant [ public array B ] { Array } } - Static properties [0] { diff --git a/ext/reflection/tests/ReflectionClass_isArray.phpt b/ext/reflection/tests/ReflectionClass_isArray.phpt new file mode 100644 index 0000000000..3eec0dac54 --- /dev/null +++ b/ext/reflection/tests/ReflectionClass_isArray.phpt @@ -0,0 +1,24 @@ +--TEST-- +public bool ReflectionParameter::isArray ( void ); +--CREDITS-- +marcosptf - <marcosptf@yahoo.com.br> - @phpsp - sao paulo - br +--FILE-- +<?php +function testReflectionIsArray($a = null, $b = 0, array $c, $d=true, array $e, $f=1.5, $g="", array $h, $i="#F989898") {} + +$reflection = new ReflectionFunction('testReflectionIsArray'); + +foreach ($reflection->getParameters() as $parameter) { + var_dump($parameter->isArray()); +} +?> +--EXPECT-- +bool(false) +bool(false) +bool(true) +bool(false) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) diff --git a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt index d3a426de4c..3ad654dd84 100644 --- a/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstanceArgs_001.phpt @@ -38,13 +38,27 @@ $rcC = new ReflectionClass('C'); $rcD = new ReflectionClass('D'); $rcE = new ReflectionClass('E'); -$a1 = $rcA->newInstanceArgs(); -$a2 = $rcA->newInstanceArgs(array('x')); -var_dump($a1, $a2); +try { + var_dump($rcA->newInstanceArgs()); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump($rcA->newInstanceArgs(array('x'))); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} -$b1 = $rcB->newInstanceArgs(); -$b2 = $rcB->newInstanceArgs(array('x', 123)); -var_dump($b1, $b2); +try { + var_dump($rcB->newInstanceArgs()); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump($rcB->newInstanceArgs(array('x', 123))); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} try { $rcC->newInstanceArgs(); @@ -73,25 +87,15 @@ try { --EXPECTF-- Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; A has a deprecated constructor in %s on line %d In constructor of class A -In constructor of class A object(A)#%d (0) { } +In constructor of class A object(A)#%d (0) { } - -Warning: Missing argument 1 for B::__construct() in %s on line 9 - -Warning: Missing argument 2 for B::__construct() in %s on line 9 - -Notice: Undefined variable: a in %s on line 10 - -Notice: Undefined variable: b in %s on line 10 -In constructor of class B with args , +Exception: Too few arguments to function B::__construct(), 0 passed and exactly 2 expected In constructor of class B with args x, 123 object(B)#%d (0) { } -object(B)#%d (0) { -} Access to non-public constructor of class C Access to non-public constructor of class D object(E)#%d (0) { diff --git a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt index afa278a9a1..e29cc8734f 100644 --- a/ext/reflection/tests/ReflectionClass_newInstance_001.phpt +++ b/ext/reflection/tests/ReflectionClass_newInstance_001.phpt @@ -42,9 +42,16 @@ $a1 = $rcA->newInstance(); $a2 = $rcA->newInstance('x'); var_dump($a1, $a2); -$b1 = $rcB->newInstance(); -$b2 = $rcB->newInstance('x', 123); -var_dump($b1, $b2); +try { + var_dump($rcB->newInstance()); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} +try { + var_dump($rcB->newInstance('x', 123)); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} try { $rcC->newInstance(); @@ -78,20 +85,10 @@ object(A)#%d (0) { } object(A)#%d (0) { } - -Warning: Missing argument 1 for B::__construct() in %s on line 9 - -Warning: Missing argument 2 for B::__construct() in %s on line 9 - -Notice: Undefined variable: a in %s on line 10 - -Notice: Undefined variable: b in %s on line 10 -In constructor of class B with args , +Exception: Too few arguments to function B::__construct(), 0 passed and exactly 2 expected In constructor of class B with args x, 123 object(B)#%d (0) { } -object(B)#%d (0) { -} Access to non-public constructor of class C Access to non-public constructor of class D object(E)#%d (0) { diff --git a/ext/reflection/tests/ReflectionClass_toString_001.phpt b/ext/reflection/tests/ReflectionClass_toString_001.phpt index b9a9b0d559..29d58420e3 100644 --- a/ext/reflection/tests/ReflectionClass_toString_001.phpt +++ b/ext/reflection/tests/ReflectionClass_toString_001.phpt @@ -12,9 +12,9 @@ echo $rc; Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { - Constants [3] { - Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } - Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } - Constant [ integer IS_FINAL ] { 4 } + Constant [ public integer IS_IMPLICIT_ABSTRACT ] { 16 } + Constant [ public integer IS_EXPLICIT_ABSTRACT ] { 32 } + Constant [ public integer IS_FINAL ] { 4 } } - Static properties [0] { @@ -34,7 +34,7 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { Property [ <default> public $name ] } - - Methods [50] { + - Methods [52] { Method [ <internal:Reflection> final private method __clone ] { - Parameters [0] { @@ -175,6 +175,12 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { } } + Method [ <internal:Reflection> public method getReflectionConstants ] { + + - Parameters [0] { + } + } + Method [ <internal:Reflection> public method getConstant ] { - Parameters [1] { @@ -182,6 +188,13 @@ Class [ <internal:Reflection> class ReflectionClass implements Reflector ] { } } + Method [ <internal:Reflection> public method getReflectionConstant ] { + + - Parameters [1] { + Parameter #0 [ <required> $name ] + } + } + Method [ <internal:Reflection> public method getInterfaces ] { - Parameters [0] { diff --git a/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClasses_basic.phpt index 4eda22a3f9..9b2122d1b9 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(14) { +array(16) { ["ReflectionException"]=> object(ReflectionClass)#2 (1) { ["name"]=> @@ -50,33 +50,43 @@ array(14) { ["name"]=> string(14) "ReflectionType" } - ["ReflectionMethod"]=> + ["ReflectionNamedType"]=> object(ReflectionClass)#10 (1) { ["name"]=> + string(19) "ReflectionNamedType" + } + ["ReflectionMethod"]=> + object(ReflectionClass)#11 (1) { + ["name"]=> string(16) "ReflectionMethod" } ["ReflectionClass"]=> - object(ReflectionClass)#11 (1) { + object(ReflectionClass)#12 (1) { ["name"]=> string(15) "ReflectionClass" } ["ReflectionObject"]=> - object(ReflectionClass)#12 (1) { + object(ReflectionClass)#13 (1) { ["name"]=> string(16) "ReflectionObject" } ["ReflectionProperty"]=> - object(ReflectionClass)#13 (1) { + object(ReflectionClass)#14 (1) { ["name"]=> string(18) "ReflectionProperty" } + ["ReflectionClassConstant"]=> + object(ReflectionClass)#15 (1) { + ["name"]=> + string(23) "ReflectionClassConstant" + } ["ReflectionExtension"]=> - object(ReflectionClass)#14 (1) { + object(ReflectionClass)#16 (1) { ["name"]=> string(19) "ReflectionExtension" } ["ReflectionZendExtension"]=> - object(ReflectionClass)#15 (1) { + object(ReflectionClass)#17 (1) { ["name"]=> string(23) "ReflectionZendExtension" } diff --git a/ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt b/ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt index ac97e3ed2a..c9d1e6379a 100644 --- a/ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt +++ b/ext/reflection/tests/ReflectionMethod_invokeArgs_error1.phpt @@ -25,12 +25,9 @@ var_dump($methodWithArgs->invokeArgs($testClassInstance, array())); --EXPECTF-- Method with args: -Warning: Missing argument 1 for TestClass::methodWithArgs() in %s on line %d - -Warning: Missing argument 2 for TestClass::methodWithArgs() in %s on line %d - -Notice: Undefined variable: a in %s on line %d - -Notice: Undefined variable: b in %s on line %d -Called methodWithArgs(, ) -NULL +Fatal error: Uncaught Error: Too few arguments to function TestClass::methodWithArgs(), 0 passed and exactly 2 expected in %sReflectionMethod_invokeArgs_error1.php:5 +Stack trace: +#0 [internal function]: TestClass->methodWithArgs() +#1 %sReflectionMethod_invokeArgs_error1.php(19): ReflectionMethod->invokeArgs(Object(TestClass), Array) +#2 {main} + thrown in %sReflectionMethod_invokeArgs_error1.php on line 5 diff --git a/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt b/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt index 513cc1845f..1222467a6b 100644 --- a/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt +++ b/ext/reflection/tests/ReflectionMethod_invokeArgs_error3.phpt @@ -14,7 +14,11 @@ class TestClass { public static function staticMethod() { echo "Called staticMethod()\n"; - var_dump($this); + try { + var_dump($this); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } } private static function privateMethod() { @@ -103,9 +107,7 @@ NULL Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, boolean given in %s on line %d NULL Called staticMethod() - -Notice: Undefined variable: this in %s on line %d -NULL +Exception: Using $this when not in object context NULL Private method: @@ -113,5 +115,4 @@ string(86) "Trying to invoke private method TestClass::privateMethod() from scop Abstract method: string(53) "Trying to invoke abstract method AbstractClass::foo()" - -Warning: ReflectionMethod::invokeArgs() expects exactly 2 parameters, 1 given in %s on line %d +string(53) "Trying to invoke abstract method AbstractClass::foo()" diff --git a/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt b/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt index cbf358c062..7bfe245f82 100644 --- a/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt +++ b/ext/reflection/tests/ReflectionMethod_invoke_basic.phpt @@ -22,7 +22,11 @@ class TestClass { public static function staticMethod() { echo "Called staticMethod()\n"; - var_dump($this); + try { + var_dump($this); + } catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; + } } private static function privateMethod() { @@ -93,15 +97,11 @@ Static method: Warning: ReflectionMethod::invoke() expects at least 1 parameter, 0 given in %s on line %d NULL -Called staticMethod() -Notice: Undefined variable: this in %s on line %d -NULL +Warning: ReflectionMethod::invoke() expects parameter 1 to be object, boolean given in %s on line %d NULL Called staticMethod() - -Notice: Undefined variable: this in %s on line %d -NULL +Exception: Using $this when not in object context NULL Method that throws an exception: diff --git a/ext/reflection/tests/ReflectionMethod_invoke_error1.phpt b/ext/reflection/tests/ReflectionMethod_invoke_error1.phpt index 758f1acd13..ef5621e7e5 100644 --- a/ext/reflection/tests/ReflectionMethod_invoke_error1.phpt +++ b/ext/reflection/tests/ReflectionMethod_invoke_error1.phpt @@ -59,7 +59,9 @@ try { ?> --EXPECTF-- invoke() on a non-object: -string(29) "Non-object passed to Invoke()" + +Warning: ReflectionMethod::invoke() expects parameter 1 to be object, boolean given in %s%eReflectionMethod_invoke_error1.php on line %d +NULL invoke() on a non-instance: string(72) "Given object is not an instance of the class this method was declared in" diff --git a/ext/reflection/tests/ReflectionMethod_invoke_error2.phpt b/ext/reflection/tests/ReflectionMethod_invoke_error2.phpt index a070c8f583..60a9ebae97 100644 --- a/ext/reflection/tests/ReflectionMethod_invoke_error2.phpt +++ b/ext/reflection/tests/ReflectionMethod_invoke_error2.phpt @@ -21,12 +21,9 @@ var_dump($methodWithArgs->invoke($testClassInstance)); --EXPECTF-- Method with args: -Warning: Missing argument 1 for TestClass::methodWithArgs() in %s on line %d - -Warning: Missing argument 2 for TestClass::methodWithArgs() in %s on line %d - -Notice: Undefined variable: a in %s on line %d - -Notice: Undefined variable: b in %s on line %d -Called methodWithArgs(, ) -NULL +Fatal error: Uncaught Error: Too few arguments to function TestClass::methodWithArgs(), 0 passed and exactly 2 expected in %sReflectionMethod_invoke_error2.php:5 +Stack trace: +#0 [internal function]: TestClass->methodWithArgs() +#1 %sReflectionMethod_invoke_error2.php(15): ReflectionMethod->invoke(Object(TestClass)) +#2 {main} + thrown in %sReflectionMethod_invoke_error2.php on line 5 diff --git a/ext/reflection/tests/ReflectionNamedType.phpt b/ext/reflection/tests/ReflectionNamedType.phpt new file mode 100644 index 0000000000..1ce1222216 --- /dev/null +++ b/ext/reflection/tests/ReflectionNamedType.phpt @@ -0,0 +1,41 @@ +--TEST-- +ReflectionNamedType::getName() and ReflectionNamedType::__toString() +--FILE-- +<?php + +function testInternalTypes(?Traversable $traversable): ?string { + return 'test'; +} + +function testUserDefinedTypes(?Test $traversable): ?Test { + return new Test; +} + +$function = new ReflectionFunction('testInternalTypes'); +$type = $function->getParameters()[0]->getType(); +$return = $function->getReturnType(); + +var_dump($type->getName()); +var_dump((string) $type); +var_dump($return->getName()); +var_dump((string) $return); + +$function = new ReflectionFunction('testUserDefinedTypes'); +$type = $function->getParameters()[0]->getType(); +$return = $function->getReturnType(); + +var_dump($type->getName()); +var_dump((string) $type); +var_dump($return->getName()); +var_dump((string) $return); + +?> +--EXPECTF-- +string(11) "Traversable" +string(13) "?\Traversable" +string(6) "string" +string(7) "?string" +string(4) "Test" +string(6) "?\Test" +string(4) "Test" +string(6) "?\Test"
\ No newline at end of file diff --git a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt b/ext/reflection/tests/ReflectionProperty_getValue_error.phpt index 62009d8bb9..c9bf0b0f25 100644 --- a/ext/reflection/tests/ReflectionProperty_getValue_error.phpt +++ b/ext/reflection/tests/ReflectionProperty_getValue_error.phpt @@ -15,7 +15,7 @@ class AnotherClass { } $instance = new TestClass(); -$instanceWithNoProperties = new AnotherClass(); +$invalidInstance = new AnotherClass(); $propInfo = new ReflectionProperty('TestClass', 'pub2'); echo "Too few args:\n"; @@ -45,9 +45,9 @@ catch(Exception $exc) { echo $exc->getMessage(); } -echo "\n\nInstance without property:\n"; +echo "\n\nInvalid instance:\n"; $propInfo = new ReflectionProperty('TestClass', 'pub2'); -var_dump($propInfo->getValue($instanceWithNoProperties)); +var_dump($propInfo->getValue($invalidInstance)); ?> --EXPECTF-- @@ -77,7 +77,10 @@ string(15) "static property" Protected property: Cannot access non-public member TestClass::prot -Instance without property: +Invalid instance: -Notice: Undefined property: AnotherClass::$pub2 in %s on line %d -NULL +Fatal error: Uncaught ReflectionException: Given object is not an instance of the class this property was declared in in %s:47 +Stack trace: +#0 %s(47): ReflectionProperty->getValue(Object(AnotherClass)) +#1 {main} + thrown in %s on line 47 diff --git a/ext/reflection/tests/ReflectionType_001.phpt b/ext/reflection/tests/ReflectionType_001.phpt index f764cf1519..c0ae24490c 100644 --- a/ext/reflection/tests/ReflectionType_001.phpt +++ b/ext/reflection/tests/ReflectionType_001.phpt @@ -79,7 +79,7 @@ foreach ([ bool(true) bool(false) bool(false) -string(8) "stdClass" +string(9) "\stdClass" ** Function 0 - Parameter 1 bool(true) bool(false) @@ -94,7 +94,7 @@ string(8) "callable" bool(true) bool(true) bool(false) -string(8) "stdClass" +string(10) "?\stdClass" ** Function 0 - Parameter 4 bool(false) ** Function 0 - Parameter 5 @@ -121,19 +121,19 @@ string(5) "float" bool(true) bool(false) bool(false) -string(11) "NotExisting" +string(12) "\NotExisting" ** Function 1 - Parameter 0 bool(true) bool(false) bool(false) -string(4) "Test" +string(5) "\Test" *** methods ** Method 0 - parameter 0 bool(true) bool(false) bool(false) -string(10) "SplSubject" +string(11) "\SplSubject" ** Method 1 - parameter 0 bool(true) bool(false) @@ -148,7 +148,7 @@ string(6) "parent" bool(true) bool(false) bool(false) -string(4) "Test" +string(5) "\Test" *** return types ** Function/method return type 0 @@ -157,7 +157,7 @@ bool(false) bool(true) bool(false) bool(false) -string(8) "stdClass" +string(9) "\stdClass" ** Function/method return type 2 bool(true) bool(false) @@ -177,9 +177,9 @@ string(6) "parent" bool(true) bool(false) bool(false) -string(4) "Test" +string(5) "\Test" ** Function/method return type 6 bool(true) bool(false) bool(false) -string(4) "Test" +string(5) "\Test" diff --git a/ext/reflection/tests/ReflectionType_002.phpt b/ext/reflection/tests/ReflectionType_002.phpt index 8313862ec5..9c9c77b76b 100644 --- a/ext/reflection/tests/ReflectionType_002.phpt +++ b/ext/reflection/tests/ReflectionType_002.phpt @@ -12,6 +12,6 @@ unset($rm, $rp); var_dump((string) $rt, (string) $rrt); --EXPECT-- -string(4) "Test" -string(5) "Test2" +string(5) "\Test" +string(6) "\Test2" diff --git a/ext/reflection/tests/ReflectionType_possible_types.phpt b/ext/reflection/tests/ReflectionType_possible_types.phpt new file mode 100644 index 0000000000..0db5b7c3f0 --- /dev/null +++ b/ext/reflection/tests/ReflectionType_possible_types.phpt @@ -0,0 +1,31 @@ +--TEST-- +ReflectionType possible types +--FILE-- +<?php + +$functions = [ + function(): void {}, + function(): int {}, + function(): float {}, + function(): string {}, + function(): bool {}, + function(): array {}, + function(): callable {}, + function(): StdClass {} +]; + +foreach ($functions as $function) { + $reflectionFunc = new ReflectionFunction($function); + $returnType = $reflectionFunc->getReturnType(); + var_dump($returnType->__toString()); +} +?> +--EXPECTF-- +string(4) "void" +string(3) "int" +string(5) "float" +string(6) "string" +string(4) "bool" +string(5) "array" +string(8) "callable" +string(9) "\StdClass" diff --git a/ext/reflection/tests/bug29986.phpt b/ext/reflection/tests/bug29986.phpt index 4c4d629f39..f5aa62a00b 100644 --- a/ext/reflection/tests/bug29986.phpt +++ b/ext/reflection/tests/bug29986.phpt @@ -20,11 +20,11 @@ Class [ <user> class just_constants ] { @@ %s %d-%d - Constants [5] { - Constant [ boolean BOOLEAN_CONSTANT ] { 1 } - Constant [ null NULL_CONSTANT ] { } - Constant [ string STRING_CONSTANT ] { This is a string } - Constant [ integer INTEGER_CONSTANT ] { 1000 } - Constant [ float FLOAT_CONSTANT ] { 3.14159265 } + Constant [ public boolean BOOLEAN_CONSTANT ] { 1 } + Constant [ public null NULL_CONSTANT ] { } + Constant [ public string STRING_CONSTANT ] { This is a string } + Constant [ public integer INTEGER_CONSTANT ] { 1000 } + Constant [ public float FLOAT_CONSTANT ] { 3.14159265 } } - Static properties [0] { diff --git a/ext/reflection/tests/bug38217.phpt b/ext/reflection/tests/bug38217.phpt index cf007d9547..988f1c8953 100644 --- a/ext/reflection/tests/bug38217.phpt +++ b/ext/reflection/tests/bug38217.phpt @@ -18,7 +18,11 @@ class Object1 { } $class= new ReflectionClass('Object1'); -var_dump($class->newInstanceArgs()); +try { + var_dump($class->newInstanceArgs()); +} catch (Throwable $e) { + echo "Exception: " . $e->getMessage() . "\n"; +} var_dump($class->newInstanceArgs(array('test'))); @@ -27,13 +31,7 @@ echo "Done\n"; --EXPECTF-- object(Object)#%d (0) { } - -Warning: Missing argument 1 for Object1::__construct() in %s on line %d - -Notice: Undefined variable: var in %s on line %d -NULL -object(Object1)#%d (0) { -} +Exception: Too few arguments to function Object1::__construct(), 0 passed and exactly 1 expected string(4) "test" object(Object1)#%d (0) { } diff --git a/ext/reflection/tests/bug45765.phpt b/ext/reflection/tests/bug45765.phpt index b0c1be2c4c..7963a03eea 100644 --- a/ext/reflection/tests/bug45765.phpt +++ b/ext/reflection/tests/bug45765.phpt @@ -31,7 +31,7 @@ Object of class [ <user> class foo extends foo2 ] { @@ %s 7-21 - Constants [1] { - Constant [ string BAR ] { foo's bar } + Constant [ public string BAR ] { foo's bar } } - Static properties [0] { diff --git a/ext/reflection/tests/bug72661.phpt b/ext/reflection/tests/bug72661.phpt new file mode 100644 index 0000000000..40d14922b8 --- /dev/null +++ b/ext/reflection/tests/bug72661.phpt @@ -0,0 +1,10 @@ +--TEST-- +Bug #72661 (ReflectionType::__toString crashes with iterable) +--FILE-- +<?php +function test(iterable $arg) { } + +var_dump((string)(new ReflectionParameter("test", 0))->getType()); +?> +--EXPECT-- +string(8) "iterable" diff --git a/ext/reflection/tests/bug72846.phpt b/ext/reflection/tests/bug72846.phpt deleted file mode 100644 index ab8b6cac79..0000000000 --- a/ext/reflection/tests/bug72846.phpt +++ /dev/null @@ -1,48 +0,0 @@ ---TEST-- -Bug #72846 (getConstant for a array constant with constant values returns NULL/NFC/UKNOWN) ---FILE-- -<?php - -namespace Some { - - abstract class A - { - const ONE = '1'; - const TWO = '2'; - - const CONST_NUMBERS = [ - self::ONE, - self::TWO, - ]; - - const NUMBERS = [ - '1', - '2', - ]; - } - - class B extends A - { - } - - $ref = new \ReflectionClass('Some\B'); - - var_dump($ref->getConstant('ONE')); - var_dump($ref->getConstant('CONST_NUMBERS')); - var_dump($ref->getConstant('NUMBERS')); -} -?> ---EXPECT-- -string(1) "1" -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" -} -array(2) { - [0]=> - string(1) "1" - [1]=> - string(1) "2" -} diff --git a/ext/reflection/tests/request38992.phpt b/ext/reflection/tests/request38992.phpt new file mode 100644 index 0000000000..8c0052fd85 --- /dev/null +++ b/ext/reflection/tests/request38992.phpt @@ -0,0 +1,22 @@ +--TEST-- +Request #38992 (invoke() and invokeArgs() static method calls should match) +--FILE-- +<?php +class MyClass +{ + public static function doSomething() + { + echo "Did it!\n"; + } +} + +$r = new ReflectionMethod('MyClass', 'doSomething'); +$r->invoke('WTF?'); +$r->invokeArgs('WTF?', array()); +?> +===DONE=== +--EXPECTF-- +Warning: ReflectionMethod::invoke() expects parameter 1 to be object, string given in %s%erequest38992.php on line %d + +Warning: ReflectionMethod::invokeArgs() expects parameter 1 to be object, string given in %s%erequest38992.php on line %d +===DONE=== |