php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #13165 Definate problem with classes and included files
Submitted: 2001-09-06 02:11 UTC Modified: 2002-06-10 04:43 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: colin at maven dot com dot au Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.0.6 OS: RedHat 7.1
Private report: No CVE-ID: None
 [2001-09-06 02:11 UTC] colin at maven dot com dot au
There is *definately* a problem in PHP 4.0.6 with classes, inheritance, and included/required files.  Here is an example:

// ======================
// test.php:

<?php

 include("children.php");

?>

// ======================

// ======================
// children.php

<?php

 include_once("parent.php");

 class Child2 extends Child1
 {

 }

 class Child1 extends Parent
 {

 }

?>

// ======================

// ======================
// parent.php

<?php

 class Parent
 {

 }

?>

// ======================

You can try this out for yourself and see what I mean.  If you bring up "test.php" in your browser, you should receive this error:

Fatal error: Class child2: Cannot inherit from undefined class child1

Why does this happen, even though all files are being included correctly?  Well, I know one way of preventing the error, and that is by re-ordering the classes in "children.php" so that Child1() is listed first.  This removes the error, **however**, if the Parent() class is NOT in a separate file, and is actually part of the same file (i.e. "children.php"), the order of the class definitions does NOT matter.  Why is this?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-09-11 01:18 UTC] colin at maven dot com dot au
Just wondering if there has been any progress on this report?  Thanks.
 [2001-10-21 20:49 UTC] sniper@php.net
This is not a bug. Classes must be defined in order.
They can be in different order if they are in same file 
though. (Zeev can explain this better :)

Reclassified as documentation problem as this isn't 
explained anywhere.

--Jani

 [2002-01-17 17:27 UTC] eye at eye-home dot net
Isn't this the same bug as http://bugs.php.net/bug.php?id=13882 (and therefore solved in version 4.1.1?)

if not it still seems a bug to me: whenever A includes B and B includes C, it should not be necessary that A has to include C
 [2002-06-10 04:43 UTC] mfischer@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 02:01:31 2024 UTC