php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37233 Includes, inheritance and interface cause error
Submitted: 2006-04-28 06:27 UTC Modified: 2006-04-28 18:58 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: paul at stunning-stuff dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.2 OS: Win XP Pro SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: paul at stunning-stuff dot com
New email:
PHP Version: OS:

 

 [2006-04-28 06:27 UTC] paul at stunning-stuff dot com
Description:
------------
I have seen 2 reports (#30452 & #30453) that seem similar to this bug. Both of them were closed with the message 'Won't fix'. I don't think this is fair, it is a bug and it should be fixed because it seriously limits the OOP capabilities of PHP5. I included a feasible real-world example that shows why this bug should be fixed (I tried to make it as short as possible).

Running index.php will cause a Fatal Error because Manager could not be found in language_manager.class.php on line 6. This happens because Manager is declared after LanguageManager is declared, even though (visually) manager.class.php is included before language_manager.class.php. The strange thing is, when Manager doesn't implement the interface Whatever, everything is fine!
If it works without an interface it should work with an interface as well.

Thanks for the time and effort you guys spend on making a great programming language. I know it's free, so I am not going to demand a fix :-), I'll just say 'pretty please' instead ;-).

Thanks,

Paul

Reproduce code:
---------------
index.php
<?php

// We require this file because we plan to use a manager object in here.
require_once 'manager.class.php';

?>

manager.class.php
<?php

// Manager implements Whatever.
require_once 'whatever.class.php';

// Manager uses LanguageManager to translate errors.
require_once 'language_manager.class.php';

class Manager implements Whatever
{
  public function functionCausingError()
  {
    // LanguageManager is used to translate an error caused in this function.
    $languageManager = new LanguageManager();
  }
}

?>

language_manager.class.php
<?php

// LanguageManager extends Manager.
require_once 'manager.class.php';

class LanguageManager extends Manager
{
}

?>

whatever.class.php
<?php

interface Whatever
{
}

?>

Expected result:
----------------
No output

Actual result:
--------------
Fatal error: Class 'Manager' not found in C:\Web Server\Web Root\sandbox\bug\language_manager.class.php on line 6

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-04-28 13:25 UTC] bjori@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 [2006-04-28 18:13 UTC] paul at stunning-stuff dot com
Did you even read my post?

"the resolution is likely to be the same." And what 'resolution' is that...? Won't fix? What am I supposed to do with a pre-compiled answer like that, if you give me one of those standard answers at least have the courtesy to read my post in its entirety. Not just the first line.

What would be a better place for me to post a request for change like the one described in my first post?

Thanks,

Paul
 [2006-04-28 18:58 UTC] bjori@php.net
> Did you even read my post?
Yes.

> And what 'resolution' is that...? Won't fix?
>What am I supposed to do with a pre-compiled answer like that
Did you read my standard answer?
This is dupe of bug #30453 and bug #30452

> What would be a better place for me to post a request for change like the one described in my first post?
It's been denied already.


You can easily get around this by moving "require_once 'language_manager.class.php';" into "functionCausingError".

And, if you have read the manual (php.net/oop5.autoload), you'd know you could also get around this like this;
function __autoload($class) {
require_once strtolower($class). ".class.php";
}


-Hannes
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jul 03 13:01:33 2024 UTC