PHP 4.0 Bug #8565 Updated: parent:: doesn't work with nested include/require
| From: | zeev@php.net | Date: | Wed, 07 Mar 2001 10:11:30 +0000 |
| Subject: | PHP 4.0 Bug #8565 Updated: parent:: doesn't work with nested include/require | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-48143@lists.php.net to get a copy of this message | ||
ID: 8565
Updated by: zeev
Reported By: jalal@php.net
Old-Status: Analyzed
Status: Closed
Bug Type: Scripting Engine problem
Assigned To:
Comments:
Fixed in the latest CVS - thanks!
Previous Comments:
---------------------------------------------------------------------------
[2001-01-08 14:10:56] stas@php.net
The reason for this is simple - parent:: is the compile-time
definition and require/include is run-time, so when it meets
parent:: it does not know yet who it's parent is. I am not
sure it's resolvable now, but I'm leaving it for Zeev/Andi's
attention.
---------------------------------------------------------------------------
[2001-01-08 10:00:11] hholzgra@php.net
it will work if you include/require/require_once both
.inc files from the file but not for nested includes
(extended class including base class to be extended)
:(
---------------------------------------------------------------------------
[2001-01-05 14:37:23] jalal@php.net
The following code gives the error:
file: base.inc
<?php
class Base {
function Base(){}
function doit() {
echo "Class Base->doit()n";
}
}
?>
file: a.inc
<?php
include("base.inc");
class A extends Base {
function A(){}
function doit() {
parent::doit();
echo "Class A->doit()n";
}
}
?>
file: extend-test.php
<?php
include("a.inc");
$a = new A();
$a->doit();
?>
x:>php -f extend-test.php
Fatal error: No parent class available in this context in a.inc on line 6
---------------------------------------------------------------------------
[2001-01-05 12:42:19] hholzgra@php.net
sorry, but i can't believe this as i
use this feature almost daily
can you pleas provide an example of
code _not_ working ?
---------------------------------------------------------------------------
[2001-01-05 12:22:36] jalal@php.net
the parent:: operator will work if both the parent and sub class are in the same physical file, but
not if they are in a separate file.
This works:
<?php
class Base {
function doit() {
echo "Class Base->doit()n";
}
}
class A extends Base {
function doit() {
parent::doit();
echo "Class A->doit()n";
}
}
?>
but if the two classes are in separate files, the following error is reported:
Fatal error: No parent class available in this context in a.inc on line 6
Of course, this may be an undocumented feature, but I can see no reason for it.
---------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view the rest of the comments,
please view the bug report online.
ATTENTION! Do NOT reply to this email!
To reply, use the web interface found at http://bugs.php.net/?id=8565&edit=2