php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8565 parent:: doesn't work with nested include/require
Submitted: 2001-01-05 12:22 UTC Modified: 2001-03-07 05:11 UTC
From: jalal@php.net Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4 OS: Linux Suse 6.4
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jalal@php.net
New email:
PHP Version: OS:

 

 [2001-01-05 12:22 UTC] 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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-01-05 12:42 UTC] 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 14:37 UTC] 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-08 10:00 UTC] 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-08 14:10 UTC] 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-03-07 05:11 UTC] zeev@php.net
Fixed in the latest CVS - thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 12 07:01:28 2024 UTC