Bug #81683 [Opn]: Misleading "access type ... must be public" interface method error message

From: Date: Sun, 05 Dec 2021 02:49:18 +0000
Subject: Bug #81683 [Opn]: Misleading "access type ... must be public" interface method error message
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-238186@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81683&edit=1 ID: 81683 Updated by: requinix@php.net Reported by: requinix@php.net Summary: Misleading "access type ... must be public" interface method error message Status: Open Type: Bug Package: Class/Object related PHP Version: 8.1.0 Block user comment: N Private report: N New Comment: Even before that PR, the message used the words "access type" when the fault could be in just the final/abstract keywords: you could add or remove a "public" like the message suggests and continue getting the same error. To fix, the message could be changed like "Interface method %s must be public, not final, and not abstract". Or the if could be split into separate public and final/abstract checks with separate error messages. Previous Comments: ------------------------------------------------------------------------ [2021-12-05 02:04:48] camporter1 at gmail dot com Seems like this might have been due to https://github.com/php/php-src/pull/7086 ? Perhaps the final and abstract keywords should have a separate message for clarity? ------------------------------------------------------------------------ [2021-12-01 09:50:34] requinix@php.net Description: ------------ https://github.com/php/php-src/blob/PHP-8.1.0/Zend/zend_compile.c#L7036 When PHP encounters an interface with a method declared non-public, it errors that the "access type for interface method %s must be public" (or "omitted" for <8.1). This is fine. But it also uses that same error message for public methods that include the final or abstract keywords, which is confusing. https://3v4l.org/otUKp Test script: --------------- <?php interface Foo { public abstract function bar(); } ?> Expected result: ---------------- Fatal error: [something about Foo::bar being marked abstract/final] in /in/otUKp on line 4 Actual result: -------------- Fatal error: Access type for interface method Foo::bar() must be public in /in/otUKp on line 4 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81683&edit=1

« previous php.bugs (#238186) next »