PHP 4.0 Bug #1851: classes defined in an include are not available in subsequent require()'ed file

From: Date: Fri, 23 Jul 1999 19:09:57 +0000
Subject: PHP 4.0 Bug #1851: classes defined in an include are not available in subsequent require()'ed file
Groups: php.dev 
Request: Send a blank email to php-dev+get-9054@lists.php.net to get a copy of this message
From: chagenbu@wso.williams.edu Operating system: RedHat Linux 6.0 PHP version: 4.0 Beta 1 PHP Bug Type: Parser error Bug description: classes defined in an include are not available in subsequent require()'ed file (I sent this to the dev list before, but I haven't heard anything so I figured I'd better do the right thing and enter it in the bugs database) Ok, this one's a bit bizarre. PHP4 Beta 1, running as an apache module (1.3.6) on RH 6.0, compiled with imap support. Here's the test script: test.php3: <?php include 'class.inc'; require 'class2.inc'; $foo = new Bar2(); echo 'foo'; ?> class.inc: <?php class Bar { function Bar () { } } ?> class2.inc: <?php class Bar2 extends Bar { var $parent; function Bar2 () { $this->Bar(); } } ?> In php3, this works fine. In php4, I get: Fatal error: Class bar2: Cannot inherit from undefined class bar in class2.inc on line 7 If both classes are required, both included, *or* the first required and the second included, it works fine. It only happens when the include comes first. Is this unavoidable due to require() being evaluated before parsing the file? But that can't be completely true since you can use a variable as an argument to require()...?

« previous php.dev (#9054) next »