]> granicus.if.org Git - php/commitdiff
Deprecate old ReflectionParameter type declaration APIs
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 25 Feb 2020 15:21:52 +0000 (16:21 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 11 May 2020 15:01:40 +0000 (17:01 +0200)
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.

12 files changed:
UPGRADING
Zend/tests/bug69802_2.phpt
Zend/tests/type_declarations/callable_002.phpt
ext/intl/tests/bug66921.phpt [deleted file]
ext/reflection/php_reflection.stub.php
ext/reflection/php_reflection_arginfo.h
ext/reflection/tests/ReflectionClass_isArray.phpt
ext/reflection/tests/bug26695.phpt
ext/reflection/tests/bug29268.phpt
ext/reflection/tests/bug39884.phpt
ext/reflection/tests/bug69802.phpt
ext/reflection/tests/parameters_002.phpt

index c6dff51274bd28553c696871873e13b14d6033b1..eba28617b37c087383f75782e4ec8e50a9a90dff 100644 (file)
--- 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
index a2de302707d716be2642c13765d0f3d78beb0943..dca35a665cfdfc5d34ed225d86531e21d4285b90 100644 (file)
@@ -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"
index 35564ff1afe5d958a1c0521ab82ac303cc64ba8e..f61955c706860d6af199fa6db94e5bc1a99702b4 100644 (file)
@@ -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 (file)
index 58ae9c0..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
---TEST--
-Bug #66921 - Wrong argument type hint for function intltz_from_date_time_zone
---SKIPIF--
-<?php if( !extension_loaded( 'intl' ) ) print 'skip'; ?>
---FILE--
-<?php
-$f = new ReflectionFunction('intltz_from_date_time_zone');
-var_dump($f->getParameters()[0]->getClass());
-
-?>
---EXPECTF--
-object(ReflectionClass)#%d (1) {
-  ["name"]=>
-  string(12) "DateTimeZone"
-}
index 1bcd4221cf3cd8db3ab456df5f2e061c10559779..e629b8d845b2558f5b7ea008ee2130985b9e030a 100644 (file)
@@ -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 */
index da896d4150ad7116707b562405e55d77e337547f..91e9c4cada36d32d54201efcb36ae9f8eb48d1f8 100644 (file)
@@ -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)
index 7c6093a55c9fea91cd23bc840a2cff6adaf49d06..4166ae71cc954381c62bc8f2842ae9864e134dbc 100644 (file)
@@ -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)
index ab61ee929fdca45d1aa509be18056c32ef32e6ad..66766c5ebb21984f6319946aacb9e894f0d47aa8 100644 (file)
@@ -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"
index 596d3aba1e20cdc1347c2cc675d88842983c0bc0..f46829be9751ab42d8dd47779b103ac4b1bc78dd 100644 (file)
@@ -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
index 1d0e04b0b9c82243ea91ec870e12cf2111ee3ece..6e73066bd44c66d4af56ebb14967866d3c659696 100644 (file)
@@ -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"
index 0a58d0b2ac72fca27b138a848197b6c2f2354840..35a0f991fa920ceaf74463cdad5979d7fbee5d74 100644 (file)
@@ -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"
index 14cb7fdefbdc444f1ce6b11806563a164b5b6ee1..f4a7ca19c6b46f6ac1c3d2b9a2f1009d3a1bfcb1 100644 (file)
@@ -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)