Skip to content

Commit 630897f

Browse files
TysonAndrecmb69
authored andcommitted
Document change to ReflectionMethod->isConstructor/isDestructor
See https://externals.io/message/109377 This prevented PHPUnit's test doubles from being created for interfaces. The reason this changed is https://github.com/php/php-src/pull/3846/files#diff-3a8139128d4026ce0cb0c86beba4e6b9L5549-R5605 (ReflectionMethod::isConstruct checks if the method is the zend_class_entry's constructor, etc.)
1 parent c33e504 commit 630897f

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

UPGRADING

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ PHP 8.0 UPGRADE NOTES
192192
- dom:
193193
. Remove unimplemented classes from ext/dom that had no behavior and contained
194194
test data. These classes have also been removed in the latest version of DOM
195-
standard:
195+
standard:
196196

197197
* DOMNameList
198198
* DomImplementationList
@@ -325,6 +325,9 @@ PHP 8.0 UPGRADE NOTES
325325
ReflectionParameter::getDefaultValue()
326326
ReflectionParameter::isDefaultValueConstant()
327327
ReflectionParameter::getDefaultValueConstantName()
328+
. ReflectionMethod::isConstructor() and ReflectionMethod::isDestructor() now
329+
also return true for `__construct` and `__destruct` in methods of interfaces.
330+
Previously, this would only be true in methods of classes and traits.
328331

329332
- Socket:
330333
. The deprecated AI_IDN_ALLOW_UNASSIGNED and AI_IDN_USE_STD3_ASCII_RULES

ext/reflection/tests/ReflectionMethod_basic1.phpt

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class DerivedClass extends TestClass {}
4949

5050
interface TestInterface {
5151
public function int();
52+
public function __construct($arg);
53+
public function __destruct();
54+
}
55+
56+
trait TestTrait {
57+
public abstract function __construct();
58+
public function __destruct() {
59+
}
5260
}
5361

5462
reflectMethod("DerivedClass", "foo");
@@ -59,6 +67,10 @@ reflectMethod("DerivedClass", "prot");
5967
reflectMethod("TestInterface", "int");
6068
reflectMethod("ReflectionProperty", "__construct");
6169
reflectMethod("TestClass", "__destruct");
70+
reflectMethod("TestInterface", "__construct");
71+
reflectMethod("TestInterface", "__destruct");
72+
reflectMethod("TestTrait", "__construct");
73+
reflectMethod("TestTrait", "__destruct");
6274

6375
?>
6476
--EXPECT--
@@ -269,6 +281,122 @@ bool(false)
269281
Reflecting on method TestClass::__destruct()
270282

271283

284+
isFinal():
285+
bool(false)
286+
287+
isAbstract():
288+
bool(false)
289+
290+
isPublic():
291+
bool(true)
292+
293+
isPrivate():
294+
bool(false)
295+
296+
isProtected():
297+
bool(false)
298+
299+
isStatic():
300+
bool(false)
301+
302+
isConstructor():
303+
bool(false)
304+
305+
isDestructor():
306+
bool(true)
307+
308+
**********************************
309+
**********************************
310+
Reflecting on method TestInterface::__construct()
311+
312+
313+
isFinal():
314+
bool(false)
315+
316+
isAbstract():
317+
bool(true)
318+
319+
isPublic():
320+
bool(true)
321+
322+
isPrivate():
323+
bool(false)
324+
325+
isProtected():
326+
bool(false)
327+
328+
isStatic():
329+
bool(false)
330+
331+
isConstructor():
332+
bool(true)
333+
334+
isDestructor():
335+
bool(false)
336+
337+
**********************************
338+
**********************************
339+
Reflecting on method TestInterface::__destruct()
340+
341+
342+
isFinal():
343+
bool(false)
344+
345+
isAbstract():
346+
bool(true)
347+
348+
isPublic():
349+
bool(true)
350+
351+
isPrivate():
352+
bool(false)
353+
354+
isProtected():
355+
bool(false)
356+
357+
isStatic():
358+
bool(false)
359+
360+
isConstructor():
361+
bool(false)
362+
363+
isDestructor():
364+
bool(true)
365+
366+
**********************************
367+
**********************************
368+
Reflecting on method TestTrait::__construct()
369+
370+
371+
isFinal():
372+
bool(false)
373+
374+
isAbstract():
375+
bool(true)
376+
377+
isPublic():
378+
bool(true)
379+
380+
isPrivate():
381+
bool(false)
382+
383+
isProtected():
384+
bool(false)
385+
386+
isStatic():
387+
bool(false)
388+
389+
isConstructor():
390+
bool(true)
391+
392+
isDestructor():
393+
bool(false)
394+
395+
**********************************
396+
**********************************
397+
Reflecting on method TestTrait::__destruct()
398+
399+
272400
isFinal():
273401
bool(false)
274402

0 commit comments

Comments
 (0)