Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109377 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 63489 invoked from network); 28 Mar 2020 09:19:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Mar 2020 09:19:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BCF6F1804E4 for ; Sat, 28 Mar 2020 00:44:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_05,SPF_HELO_NONE, SPF_NEUTRAL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS20694 188.94.24.0/21 X-Spam-Virus: No X-Envelope-From: Received: from scarlet.netpirates.net (scarlet.netpirates.net [188.94.27.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 28 Mar 2020 00:44:54 -0700 (PDT) Received: from p579cd599.dip0.t-ipconnect.de ([87.156.213.153] helo=linux.fritz.box) by scarlet.netpirates.net with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1jI69F-000892-3Z for internals@lists.php.net; Sat, 28 Mar 2020 08:44:53 +0100 To: internals@lists.php.net Reply-To: internals@lists.php.net Message-ID: Date: Sat, 28 Mar 2020 08:44:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Interfaces and ReflectionMethod::isConstructor() From: sebastian@php.net (Sebastian Bergmann) 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: 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