php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51803 Interface implementation silently fails
Submitted: 2010-05-12 21:55 UTC Modified: 2010-05-13 17:35 UTC
From: kherge at me dot com Assigned:
Status: Not a bug Package: Reproducible crash
PHP Version: 5.3.2 OS: Windows XP SP3
Private report: No CVE-ID: None
 [2010-05-12 21:55 UTC] kherge at me dot com
Description:
------------
Running the test script, PHP silently exists with the error code 255.  If you 
remove the protected access type from the _test() function in the MyClass class, 
the script executes normally.

Test script:
---------------
<?php

    interface MyInterface
    {
        function _test ( );
        function test ( );
    }
    class MyClass implements MyInterface
    {
        protected function _test ( )
        {
            echo 'My _test() function', "\n";
        }
        public function test ( )
        {
            self::_test( );
        }
    }

    MyClass::test( );

Expected result:
----------------
Output: "My _test() function"

Actual result:
--------------
PHP exits with %ERRORLEVEL% = 255

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-05-12 22:05 UTC] dtajchreber@php.net
-Status: Open +Status: Feedback
 [2010-05-12 22:05 UTC] dtajchreber@php.net
Do you have error reporting settings at the right level.. display errors? I get a nice fatal error as expected..

david@beirut:~$ php test.php 
PHP Fatal error:  Access level to MyClass::_test() must be public (as in class MyInterface) in /home/david/test.php on line 9

Fatal error: Access level to MyClass::_test() must be public (as in class MyInterface) in /home/david/test.php on line 9
david@beirut:~$ echo $?
255
 [2010-05-12 22:09 UTC] kherge at me dot com
Error reporting is currently set to 32767 (E_ALL | E_STRICT).
 [2010-05-12 22:43 UTC] dtajchreber@php.net
Ditto on reproducing it.

C:\Documents and Settings\David\Desktop\php-5.3.2-Win32-VC6-x86>php ..\test.php

Fatal error: Access level to MyClass::_test() must be public (as in class MyInte
rface) in C:\Documents and Settings\David\Desktop\test.php on line 9

C:\Documents and Settings\David\Desktop\php-5.3.2-Win32-VC6-x86>echo %ERRORLEVEL%
255

I think it's a configuration issue on your end. Check your error log/display error settings. Your class has to implement the method the way that the interface describes it. Your interface defaults to public for _test() and test() but you alter that.. a simpler test case:

class A implements Iterator {
 private function next() { }
}

should yield the same error as in your example.
 [2010-05-13 17:35 UTC] dtajchreber@php.net
-Status: Feedback +Status: Bogus
 [2010-05-13 17:35 UTC] dtajchreber@php.net
Closing as bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC