php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54327 Interface extending problem
Submitted: 2011-03-21 00:00 UTC Modified: 2011-03-22 11:03 UTC
From: j dot verloop at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.6 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: j dot verloop at gmail dot com
New email:
PHP Version: OS:

 

 [2011-03-21 00:00 UTC] j dot verloop at gmail dot com
Description:
------------
PHP can't seem to find an interface when it's extended by another one and 
implemented by a class located in a different namespace (when stored in 1 single 
file).

Test script:
---------------
I do have 3 examples:

Example 1:

test.php

namespace A;

class B implements \A\B\C, \Countable {
    public function count() {
        return 1;
    }
}

namespace A\B;

interface C {}

everything is OK!
-----------------

Example 2:

test.php

namespace A\B;

interface C extends \Countable {}

namespace A;

class B implements \A\B\C {
    public function count() {
        return 1;
    }
}

everything is OK!
-----------------

Example 3:

test.php

namespace A;

class B implements \A\B\C {
    public function count() {
        return 1;
    }
}

namespace A\B;

interface C extends \Countable {}

Fatal error

Expected result:
----------------
No fatal error ;)

Actual result:
--------------
Fatal error: Interface 'A\B\C' not found in...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-21 02:45 UTC] felipe@php.net
-Status: Open +Status: Bogus
 [2011-03-21 02:45 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is expected, for such case you need to implement the interface before using it.

<?php

namespace A\B;
interface z { }
interface C extends z {}

namespace A;
class B implements \A\B\C { }
 [2011-03-21 09:19 UTC] j dot verloop at gmail dot com
Thanks for your reply!
Btw, it´s not namespace related because I've found the same *problem* without 
using namespaces.
You say it´s expected behaviour, so I suppose you´re right. But isn't it weird 
the problem doesn't occur in the *same* inheritance structure when we only use 
classes.

// Only classes
class A extends B {}

class C {}

class B extends C {}

everything is OK!
-----------------

// Classes and interfaces
class D implements E {}

interface F {}

interface E extends F {}

Fatal error: Interface 'E' not found in...
------------------------------------------

I've searched the documentation to clarify this issue as expected.
Obviously, I haven't found it. I would appreciate it if you could point me in 
the right direction (documentation).
 [2011-03-22 11:03 UTC] j dot verloop at gmail dot com
-Operating System: OSX +Operating System: *
 [2011-03-22 11:03 UTC] j dot verloop at gmail dot com
Changed to all platforms
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 15 09:00:01 2025 UTC