I recently received a bug report for PHPUnit [1] that with PHP 8 test doubles (test stubs or mock objects) can no longer be created for interfaces that declare a constructor.
I was able to reproduce this [2] and learned that PHPUnit's canMockMethod() [3] returns a different result on PHP 8 compared to PHP 7. This is due to the return value of ReflectionMethod::isConstructor() when the ReflectionMethod object was created for an interface. Here is a minimal, self-contained, reproducing test case: <?php interface I { public function __construct(); } var_dump((new ReflectionMethod(I::class, '__construct'))->isConstructor()); The code shown above yields the following result: * bool(true) for PHP 5.0.0 and PHP 5.0.1 * bool(false) for PHP 5.0.2 through PHP 7.4.4 * bool(true) for PHP 8.0-dev I think that the behaviour in PHP 8 (and PHP 5.0.0 and PHP 5.0.1) is correct. But I also think that constructor declarations have no place in interfaces ... so I am confused. Which is why I did not open a ticket on bugs.php.net and bring this topic to this list instead. To the best of my knowledge, this change in behaviour of isConstructor() between PHP 7 and PHP 8 is not yet documented. If it is intentional and here to stay then it should be documented. I can deal with this in PHPUnit's code either way, but need to know what the plan here is. Thanks! Sebastian -- [1] https://github.com/sebastianbergmann/phpunit/issues/4139 [2] https://github.com/sebastianbergmann/phpunit/issues/4139#issuecomment-605407253 [3] https://github.com/sebastianbergmann/phpunit/blob/9.0.1/src/Framework/MockObject/Generator.php#L861 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php