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"

ext/reflection/tests/bug69802.phpt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ echo $r->getParameters()[0], "\n";
1010
echo $r->getReturnType()->getName(), "\n";
1111
echo $r,"\n";
1212
?>
13-
--EXPECT--
13+
--EXPECTF--
1414
string(1) "x"
15+
16+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
1517
object(ReflectionClass)#4 (1) {
1618
["name"]=>
1719
string(8) "stdClass"

ext/reflection/tests/parameters_002.phpt

Lines changed: 71 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,69 +72,97 @@ check_params(new ReflectionFunction('test'));
7272
check_params(new ReflectionMethod('test::method'));
7373

7474
?>
75-
--EXPECT--
75+
--EXPECTF--
7676
#####test()#####
7777
===0===
7878
getName: string(3) "nix"
7979
isPassedByReference: bool(false)
80+
81+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
8082
getClass: NULL
8183
getDeclaringClass: NULL
82-
isArray: bool(false)
84+
isArray:
85+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
86+
bool(false)
8387
allowsNull: bool(true)
8488
isOptional: bool(false)
8589
isDefaultValueAvailable: bool(false)
8690
===1===
8791
getName: string(2) "ar"
8892
isPassedByReference: bool(false)
93+
94+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
8995
getClass: NULL
9096
getDeclaringClass: NULL
91-
isArray: bool(true)
97+
isArray:
98+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
99+
bool(true)
92100
allowsNull: bool(false)
93101
isOptional: bool(false)
94102
isDefaultValueAvailable: bool(false)
95103
===2===
96104
getName: string(3) "ref"
97105
isPassedByReference: bool(true)
106+
107+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
98108
getClass: NULL
99109
getDeclaringClass: NULL
100-
isArray: bool(false)
110+
isArray:
111+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
112+
bool(false)
101113
allowsNull: bool(true)
102114
isOptional: bool(false)
103115
isDefaultValueAvailable: bool(false)
104116
===3===
105117
getName: string(3) "std"
106118
isPassedByReference: bool(false)
119+
120+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
107121
getClass: stdClass
108122
getDeclaringClass: NULL
109-
isArray: bool(false)
123+
isArray:
124+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
125+
bool(false)
110126
allowsNull: bool(false)
111127
isOptional: bool(false)
112128
isDefaultValueAvailable: bool(false)
113129
===4===
114130
getName: string(2) "na"
115131
isPassedByReference: bool(false)
132+
133+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
116134
Class NonExistingClass does not exist
117135
getDeclaringClass: NULL
118-
isArray: bool(false)
136+
isArray:
137+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
138+
bool(false)
119139
allowsNull: bool(false)
120140
isOptional: bool(false)
121141
isDefaultValueAvailable: bool(false)
122142
===5===
123143
getName: string(3) "opt"
124144
isPassedByReference: bool(true)
145+
146+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
125147
getClass: stdClass
126148
getDeclaringClass: NULL
127-
isArray: bool(false)
149+
isArray:
150+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
151+
bool(false)
128152
allowsNull: bool(true)
129153
isOptional: bool(true)
130154
isDefaultValueAvailable: bool(true)
131155
getDefaultValue: NULL
132156
===6===
133157
getName: string(3) "def"
134158
isPassedByReference: bool(false)
159+
160+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
135161
getClass: NULL
136162
getDeclaringClass: NULL
137-
isArray: bool(false)
163+
isArray:
164+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
165+
bool(false)
138166
allowsNull: bool(true)
139167
isOptional: bool(true)
140168
isDefaultValueAvailable: bool(true)
@@ -143,64 +171,92 @@ getDefaultValue: string(6) "FooBar"
143171
===0===
144172
getName: string(3) "nix"
145173
isPassedByReference: bool(false)
174+
175+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
146176
getClass: NULL
147177
getDeclaringClass: test
148-
isArray: bool(false)
178+
isArray:
179+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
180+
bool(false)
149181
allowsNull: bool(true)
150182
isOptional: bool(false)
151183
isDefaultValueAvailable: bool(false)
152184
===1===
153185
getName: string(2) "ar"
154186
isPassedByReference: bool(false)
187+
188+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
155189
getClass: NULL
156190
getDeclaringClass: test
157-
isArray: bool(true)
191+
isArray:
192+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
193+
bool(true)
158194
allowsNull: bool(false)
159195
isOptional: bool(false)
160196
isDefaultValueAvailable: bool(false)
161197
===2===
162198
getName: string(3) "ref"
163199
isPassedByReference: bool(true)
200+
201+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
164202
getClass: NULL
165203
getDeclaringClass: test
166-
isArray: bool(false)
204+
isArray:
205+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
206+
bool(false)
167207
allowsNull: bool(true)
168208
isOptional: bool(false)
169209
isDefaultValueAvailable: bool(false)
170210
===3===
171211
getName: string(3) "std"
172212
isPassedByReference: bool(false)
213+
214+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
173215
getClass: stdClass
174216
getDeclaringClass: test
175-
isArray: bool(false)
217+
isArray:
218+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
219+
bool(false)
176220
allowsNull: bool(false)
177221
isOptional: bool(false)
178222
isDefaultValueAvailable: bool(false)
179223
===4===
180224
getName: string(2) "na"
181225
isPassedByReference: bool(false)
226+
227+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
182228
Class NonExistingClass does not exist
183229
getDeclaringClass: test
184-
isArray: bool(false)
230+
isArray:
231+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
232+
bool(false)
185233
allowsNull: bool(false)
186234
isOptional: bool(false)
187235
isDefaultValueAvailable: bool(false)
188236
===5===
189237
getName: string(3) "opt"
190238
isPassedByReference: bool(false)
239+
240+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
191241
getClass: stdClass
192242
getDeclaringClass: test
193-
isArray: bool(false)
243+
isArray:
244+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
245+
bool(false)
194246
allowsNull: bool(true)
195247
isOptional: bool(true)
196248
isDefaultValueAvailable: bool(true)
197249
getDefaultValue: NULL
198250
===6===
199251
getName: string(3) "def"
200252
isPassedByReference: bool(false)
253+
254+
Deprecated: Function ReflectionParameter::getClass() is deprecated in %s on line %d
201255
getClass: NULL
202256
getDeclaringClass: test
203-
isArray: bool(false)
257+
isArray:
258+
Deprecated: Function ReflectionParameter::isArray() is deprecated in %s on line %d
259+
bool(false)
204260
allowsNull: bool(true)
205261
isOptional: bool(true)
206262
isDefaultValueAvailable: bool(true)

0 commit comments

Comments
 (0)