From: Nikita Popov Date: Tue, 25 Feb 2020 15:21:52 +0000 (+0100) Subject: Deprecate old ReflectionParameter type declaration APIs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28af364d2ae2261addc21f8830f175baa8fa72cf;p=php Deprecate old ReflectionParameter type declaration APIs This deprecates: ReflectionParameter::isArray() ReflectionParameter::isCallable() ReflectionParameter::getClass() These APIs have been superseded by ReflectionParameter::getType() since PHP 7.0. Types introduced since that time are not available through the old APIs, and their behavior is getting increasingly confusing. This is how they interact with PHP 8 union types: * isArray() will return true if the type is array or ?array, but not any other union type * Same for isCallable(). * getClass() will return a class for T|int etc, as long as the union only contains a single type. T1|T2 will return null. This behavior is not particularly reasonable or useful, and will get more confusing as new type system extensions are added. Closes GH-5209. --- diff --git a/UPGRADING b/UPGRADING index c6dff51274..eba28617b3 100644 --- a/UPGRADING +++ b/UPGRADING @@ -548,6 +548,10 @@ PHP 8.0 UPGRADE NOTES . ReflectionFunction::isDisabled() is deprecated, as it is no longer possible to create a ReflectionFunction for a disabled function. This method now always returns false. + . ReflectionParameter::getClass(), ReflectionParameter::isArray(), and + ReflectionParameter::isCallable() are deprecated. + ReflectionParameter::getType() and the ReflectionType APIs should be used + instead. ======================================== 5. Changed Functions diff --git a/Zend/tests/bug69802_2.phpt b/Zend/tests/bug69802_2.phpt index a2de302707..dca35a665c 100644 --- a/Zend/tests/bug69802_2.phpt +++ b/Zend/tests/bug69802_2.phpt @@ -6,7 +6,8 @@ $f = (new ReflectionFunction('iterator_to_array'))->getClosure(); $r = new ReflectionMethod($f, '__invoke'); var_dump($r->getParameters()[0]->getClass()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d object(ReflectionClass)#4 (1) { ["name"]=> string(11) "Traversable" diff --git a/Zend/tests/type_declarations/callable_002.phpt b/Zend/tests/type_declarations/callable_002.phpt index 35564ff1af..f61955c706 100644 --- a/Zend/tests/type_declarations/callable_002.phpt +++ b/Zend/tests/type_declarations/callable_002.phpt @@ -20,7 +20,12 @@ $rc = new ReflectionFunction($closure); var_dump($rc->getParameters()[0]->isCallable()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d bool(true) + +Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d bool(true) + +Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d bool(true) diff --git a/ext/intl/tests/bug66921.phpt b/ext/intl/tests/bug66921.phpt deleted file mode 100644 index 58ae9c0f82..0000000000 --- a/ext/intl/tests/bug66921.phpt +++ /dev/null @@ -1,15 +0,0 @@ ---TEST-- -Bug #66921 - Wrong argument type hint for function intltz_from_date_time_zone ---SKIPIF-- - ---FILE-- -getParameters()[0]->getClass()); - -?> ---EXPECTF-- -object(ReflectionClass)#%d (1) { - ["name"]=> - string(12) "DateTimeZone" -} diff --git a/ext/reflection/php_reflection.stub.php b/ext/reflection/php_reflection.stub.php index 1bcd4221cf..e629b8d845 100644 --- a/ext/reflection/php_reflection.stub.php +++ b/ext/reflection/php_reflection.stub.php @@ -493,7 +493,10 @@ class ReflectionParameter implements Reflector /** @return ReflectionClass|null */ public function getDeclaringClass() {} - /** @return ReflectionClass|null */ + /** + * @return ReflectionClass|null + * @deprecated Use ReflectionParameter::getType() instead + */ public function getClass() {} /** @return bool */ @@ -502,10 +505,16 @@ class ReflectionParameter implements Reflector /** @return ReflectionType|null */ public function getType() {} - /** @return bool */ + /** + * @return bool + * @deprecated Use ReflectionParameter::getType() instead + */ public function isArray() {} - /** @return bool */ + /** + * @return bool + * @deprecated Use ReflectionParameter::getType() instead + */ public function isCallable() {} /** @return bool */ diff --git a/ext/reflection/php_reflection_arginfo.h b/ext/reflection/php_reflection_arginfo.h index da896d4150..91e9c4cada 100644 --- a/ext/reflection/php_reflection_arginfo.h +++ b/ext/reflection/php_reflection_arginfo.h @@ -850,11 +850,11 @@ static const zend_function_entry class_ReflectionParameter_methods[] = { ZEND_ME(ReflectionParameter, canBePassedByValue, arginfo_class_ReflectionParameter_canBePassedByValue, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionParameter, getDeclaringFunction, arginfo_class_ReflectionParameter_getDeclaringFunction, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionParameter, getDeclaringClass, arginfo_class_ReflectionParameter_getDeclaringClass, ZEND_ACC_PUBLIC) - ZEND_ME(ReflectionParameter, getClass, arginfo_class_ReflectionParameter_getClass, ZEND_ACC_PUBLIC) + ZEND_ME(ReflectionParameter, getClass, arginfo_class_ReflectionParameter_getClass, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(ReflectionParameter, hasType, arginfo_class_ReflectionParameter_hasType, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionParameter, getType, arginfo_class_ReflectionParameter_getType, ZEND_ACC_PUBLIC) - ZEND_ME(ReflectionParameter, isArray, arginfo_class_ReflectionParameter_isArray, ZEND_ACC_PUBLIC) - ZEND_ME(ReflectionParameter, isCallable, arginfo_class_ReflectionParameter_isCallable, ZEND_ACC_PUBLIC) + ZEND_ME(ReflectionParameter, isArray, arginfo_class_ReflectionParameter_isArray, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) + ZEND_ME(ReflectionParameter, isCallable, arginfo_class_ReflectionParameter_isCallable, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED) ZEND_ME(ReflectionParameter, allowsNull, arginfo_class_ReflectionParameter_allowsNull, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionParameter, getPosition, arginfo_class_ReflectionParameter_getPosition, ZEND_ACC_PUBLIC) ZEND_ME(ReflectionParameter, isOptional, arginfo_class_ReflectionParameter_isOptional, ZEND_ACC_PUBLIC) diff --git a/ext/reflection/tests/ReflectionClass_isArray.phpt b/ext/reflection/tests/ReflectionClass_isArray.phpt index 7c6093a55c..4166ae71cc 100644 --- a/ext/reflection/tests/ReflectionClass_isArray.phpt +++ b/ext/reflection/tests/ReflectionClass_isArray.phpt @@ -13,8 +13,15 @@ foreach ($reflection->getParameters() as $parameter) { var_dump($parameter->isArray()); } ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d bool(true) + +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d bool(true) + +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d bool(false) + +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d bool(false) diff --git a/ext/reflection/tests/bug26695.phpt b/ext/reflection/tests/bug26695.phpt index ab61ee929f..66766c5ebb 100644 --- a/ext/reflection/tests/bug26695.phpt +++ b/ext/reflection/tests/bug26695.phpt @@ -19,5 +19,6 @@ $class = $params[0]->getClass(); var_dump($class->getName()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d string(3) "Foo" diff --git a/ext/reflection/tests/bug29268.phpt b/ext/reflection/tests/bug29268.phpt index 596d3aba1e..f46829be97 100644 --- a/ext/reflection/tests/bug29268.phpt +++ b/ext/reflection/tests/bug29268.phpt @@ -21,7 +21,8 @@ foreach($parameters as $parameter) } echo "ok\n"; ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d __autoload(A) A ok diff --git a/ext/reflection/tests/bug39884.phpt b/ext/reflection/tests/bug39884.phpt index 1d0e04b0b9..6e73066bd4 100644 --- a/ext/reflection/tests/bug39884.phpt +++ b/ext/reflection/tests/bug39884.phpt @@ -15,7 +15,8 @@ $test1->paramTest($test2); $refParam = new ReflectionParameter(array('stubParamTest', 'paramTest'), 'param'); var_dump($refParam->getClass()); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d object(ReflectionClass)#4 (1) { ["name"]=> string(13) "stubParamTest" diff --git a/ext/reflection/tests/bug69802.phpt b/ext/reflection/tests/bug69802.phpt index 0a58d0b2ac..35a0f991fa 100644 --- a/ext/reflection/tests/bug69802.phpt +++ b/ext/reflection/tests/bug69802.phpt @@ -10,8 +10,10 @@ echo $r->getParameters()[0], "\n"; echo $r->getReturnType()->getName(), "\n"; echo $r,"\n"; ?> ---EXPECT-- +--EXPECTF-- string(1) "x" + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d object(ReflectionClass)#4 (1) { ["name"]=> string(8) "stdClass" diff --git a/ext/reflection/tests/parameters_002.phpt b/ext/reflection/tests/parameters_002.phpt index 14cb7fdefb..f4a7ca19c6 100644 --- a/ext/reflection/tests/parameters_002.phpt +++ b/ext/reflection/tests/parameters_002.phpt @@ -72,59 +72,83 @@ check_params(new ReflectionFunction('test')); check_params(new ReflectionMethod('test::method')); ?> ---EXPECT-- +--EXPECTF-- #####test()##### ===0=== getName: string(3) "nix" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===1=== getName: string(2) "ar" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: NULL -isArray: bool(true) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(true) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===2=== getName: string(3) "ref" isPassedByReference: bool(true) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===3=== getName: string(3) "std" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: stdClass getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===4=== getName: string(2) "na" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d Class NonExistingClass does not exist getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===5=== getName: string(3) "opt" isPassedByReference: bool(true) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: stdClass getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(true) isDefaultValueAvailable: bool(true) @@ -132,9 +156,13 @@ getDefaultValue: NULL ===6=== getName: string(3) "def" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: NULL -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(true) isDefaultValueAvailable: bool(true) @@ -143,54 +171,78 @@ getDefaultValue: string(6) "FooBar" ===0=== getName: string(3) "nix" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===1=== getName: string(2) "ar" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: test -isArray: bool(true) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(true) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===2=== getName: string(3) "ref" isPassedByReference: bool(true) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===3=== getName: string(3) "std" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: stdClass getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===4=== getName: string(2) "na" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d Class NonExistingClass does not exist getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(false) isOptional: bool(false) isDefaultValueAvailable: bool(false) ===5=== getName: string(3) "opt" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: stdClass getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(true) isDefaultValueAvailable: bool(true) @@ -198,9 +250,13 @@ getDefaultValue: NULL ===6=== getName: string(3) "def" isPassedByReference: bool(false) + +Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d getClass: NULL getDeclaringClass: test -isArray: bool(false) +isArray: +Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d +bool(false) allowsNull: bool(true) isOptional: bool(true) isDefaultValueAvailable: bool(true)