php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81683 Misleading "access type ... must be public" interface method error message
Submitted: 2021-12-01 09:50 UTC Modified: 2021-12-05 22:51 UTC
From: requinix@php.net Assigned: ilutov (profile)
Status: Closed Package: Class/Object related
PHP Version: 8.1.0 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: requinix@php.net
New email:
PHP Version: OS:

 

 [2021-12-01 09:50 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-12-05 02:04 UTC] 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-05 02:49 UTC] requinix@php.net
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.
 [2021-12-05 19:24 UTC] ilutov@php.net
-Assigned To: +Assigned To: ilutov
 [2021-12-05 19:24 UTC] ilutov@php.net
-Status: Assigned +Status: Verified
 [2021-12-05 22:51 UTC] ilutov@php.net
-Status: Verified +Status: Closed
 [2021-12-05 22:51 UTC] ilutov@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at
http://www.php.net/downloads.php

Will be fixed in PHP 8.1.2. Thanks for the report!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC