Skip to content

Commit 28af364

Browse files
committed
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.
1 parent 4865592 commit 28af364

File tree

12 files changed

+115
-43
lines changed

12 files changed

+115
-43
lines changed

UPGRADING

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,10 @@ PHP 8.0 UPGRADE NOTES
548548
. ReflectionFunction::isDisabled() is deprecated, as it is no longer possible
549549
to create a ReflectionFunction for a disabled function. This method now
550550
always returns false.
551+
. ReflectionParameter::getClass(), ReflectionParameter::isArray(), and
552+
ReflectionParameter::isCallable() are deprecated.
553+
ReflectionParameter::getType() and the ReflectionType APIs should be used
554+
instead.
551555

552556
========================================
553557
5. Changed Functions

Zend/tests/bug69802_2.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ $f = (new ReflectionFunction('iterator_to_array'))->getClosure();
66
$r = new ReflectionMethod($f, '__invoke');
77
var_dump($r->getParameters()[0]->getClass());
88
?>
9-
--EXPECT--
9+
--EXPECTF--
10+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
1011
object(ReflectionClass)#4 (1) {
1112
["name"]=>
1213
string(11) "Traversable"

Zend/tests/type_declarations/callable_002.phpt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ $rc = new ReflectionFunction($closure);
2020
var_dump($rc->getParameters()[0]->isCallable());
2121

2222
?>
23-
--EXPECT--
23+
--EXPECTF--
24+
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
2425
bool(true)
26+
27+
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
2528
bool(true)
29+
30+
Deprecated: Function ReflectionParameter::isCallable() is deprecated in %s on line %d
2631
bool(true)

ext/intl/tests/bug66921.phpt

Lines changed: 0 additions & 15 deletions
This file was deleted.

ext/reflection/php_reflection.stub.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ public function getDeclaringFunction() {}
493493
/** @return ReflectionClass|null */
494494
public function getDeclaringClass() {}
495495

496-
/** @return ReflectionClass|null */
496+
/**
497+
* @return ReflectionClass|null
498+
* @deprecated Use ReflectionParameter::getType() instead
499+
*/
497500
public function getClass() {}
498501

499502
/** @return bool */
@@ -502,10 +505,16 @@ public function hasType() {}
502505
/** @return ReflectionType|null */
503506
public function getType() {}
504507

505-
/** @return bool */
508+
/**
509+
* @return bool
510+
* @deprecated Use ReflectionParameter::getType() instead
511+
*/
506512
public function isArray() {}
507513

508-
/** @return bool */
514+
/**
515+
* @return bool
516+
* @deprecated Use ReflectionParameter::getType() instead
517+
*/
509518
public function isCallable() {}
510519

511520
/** @return bool */

ext/reflection/php_reflection_arginfo.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,11 @@ static const zend_function_entry class_ReflectionParameter_methods[] = {
850850
ZEND_ME(ReflectionParameter, canBePassedByValue, arginfo_class_ReflectionParameter_canBePassedByValue, ZEND_ACC_PUBLIC)
851851
ZEND_ME(ReflectionParameter, getDeclaringFunction, arginfo_class_ReflectionParameter_getDeclaringFunction, ZEND_ACC_PUBLIC)
852852
ZEND_ME(ReflectionParameter, getDeclaringClass, arginfo_class_ReflectionParameter_getDeclaringClass, ZEND_ACC_PUBLIC)
853-
ZEND_ME(ReflectionParameter, getClass, arginfo_class_ReflectionParameter_getClass, ZEND_ACC_PUBLIC)
853+
ZEND_ME(ReflectionParameter, getClass, arginfo_class_ReflectionParameter_getClass, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
854854
ZEND_ME(ReflectionParameter, hasType, arginfo_class_ReflectionParameter_hasType, ZEND_ACC_PUBLIC)
855855
ZEND_ME(ReflectionParameter, getType, arginfo_class_ReflectionParameter_getType, ZEND_ACC_PUBLIC)
856-
ZEND_ME(ReflectionParameter, isArray, arginfo_class_ReflectionParameter_isArray, ZEND_ACC_PUBLIC)
857-
ZEND_ME(ReflectionParameter, isCallable, arginfo_class_ReflectionParameter_isCallable, ZEND_ACC_PUBLIC)
856+
ZEND_ME(ReflectionParameter, isArray, arginfo_class_ReflectionParameter_isArray, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
857+
ZEND_ME(ReflectionParameter, isCallable, arginfo_class_ReflectionParameter_isCallable, ZEND_ACC_PUBLIC|ZEND_ACC_DEPRECATED)
858858
ZEND_ME(ReflectionParameter, allowsNull, arginfo_class_ReflectionParameter_allowsNull, ZEND_ACC_PUBLIC)
859859
ZEND_ME(ReflectionParameter, getPosition, arginfo_class_ReflectionParameter_getPosition, ZEND_ACC_PUBLIC)
860860
ZEND_ME(ReflectionParameter, isOptional, arginfo_class_ReflectionParameter_isOptional, ZEND_ACC_PUBLIC)

ext/reflection/tests/ReflectionClass_isArray.phpt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ foreach ($reflection->getParameters() as $parameter) {
1313
var_dump($parameter->isArray());
1414
}
1515
?>
16-
--EXPECT--
16+
--EXPECTF--
17+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
1718
bool(true)
19+
20+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
1821
bool(true)
22+
23+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
1924
bool(false)
25+
26+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
2027
bool(false)

ext/reflection/tests/bug26695.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ $class = $params[0]->getClass();
1919

2020
var_dump($class->getName());
2121
?>
22-
--EXPECT--
22+
--EXPECTF--
23+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
2324
string(3) "Foo"

ext/reflection/tests/bug29268.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ foreach($parameters as $parameter)
2121
}
2222
echo "ok\n";
2323
?>
24-
--EXPECT--
24+
--EXPECTF--
25+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
2526
__autoload(A)
2627
A
2728
ok

ext/reflection/tests/bug39884.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ $test1->paramTest($test2);
1515
$refParam = new ReflectionParameter(array('stubParamTest', 'paramTest'), 'param');
1616
var_dump($refParam->getClass());
1717
?>
18-
--EXPECT--
18+
--EXPECTF--
19+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
1920
object(ReflectionClass)#4 (1) {
2021
["name"]=>
2122
string(13) "stubParamTest"

0 commit comments

Comments
 (0)