| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 03:00:01 2025 UTC | 
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