Bug #13165: Definate problem with classes and included files
| From: | colin at maven dot com dot au | Date: | Thu, 06 Sep 2001 06:11:38 +0000 |
| Subject: | Bug #13165: Definate problem with classes and included files | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-65211@lists.php.net to get a copy of this message | ||
From: colin@maven.com.au
Operating system: RedHat 7.1
PHP version: 4.0.6
PHP Bug Type: Class/Object related
Bug description: Definate problem with classes and included files
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?
--
Edit bug report at: http://bugs.php.net/?id=13165&edit=1