php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51395 implemeting an interface causes class not found
Submitted: 2010-03-25 23:12 UTC Modified: 2010-03-25 23:55 UTC
From: johnston dot joshua at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: OS X, FreeBSD
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: johnston dot joshua at gmail dot com
New email:
PHP Version: OS:

 

 [2010-03-25 23:12 UTC] johnston dot joshua at gmail dot com
Description:
------------
Normally you can declare classes in any order inside of a php file. When one of your classes implements an interface, php will throw a fatal error about class not found if the class is declared in the wrong order.

If you remove the implements clause then order does not matter.

php bug http://bugs.php.net/bug.php?id=39758 also shows this and the reply from dmitry was:

PHP always declares classes those implement interfaces at run-time. So in your example you cannot declare "Bar" because "Foo" is not declared yet.
Your report may be categorised as "feature request", but it cannot be fixed in 5.2.* anyway, because of binary compatibility.


Just because the internals handle things in a certain order does not mean that php should exhibit contradicting behavior based on valid class definitions.

Test script:
---------------
test.php
<?php
class One extends Two {}
interface Three {}
class Two implements Three {}
?>

test2.php
<?php
class One extends Two {}
interface Three {}
class Two {}
?>

Expected result:
----------------
test.php:
no output

test2.php:
no output

Actual result:
--------------
jjohnston:~$ php test.php 
PHP Fatal error:  Class 'Two' not found in /Users/jjohnston/test.php on line 2

Fatal error: Class 'Two' not found in /Users/jjohnston/test.php on line 2

jjohnston:~$ php test2.php

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-25 23:55 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-03-25 23:55 UTC] johannes@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 a documented limitation of the object implementation and the way we do object binding.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Aug 06 10:00:02 2025 UTC