|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-11-21 09:55 UTC] imkow at 163 dot com
Description:
------------
Two files:
file1.php:
class A{}
file2.php?F
require("file1.php");
$obj=new B;
class B extends A{}
when runing file2.php, it throws a Fatal Error, saying Class B can't be found in the line where "$obj=new B;" is.
But, in following code, things will just be fine:
class A{}
$obj=new B;
class B extends A{}
I use an official release of PHP 5.2.0 under windows. All mods are also from Pecl.
Reproduce code:
---------------
//file1.php:
class A{}
//file2.php?F
require("file1.php");
$obj=new B;
class B extends A{}
Expected result:
----------------
nothing..
Actual result:
--------------
( ! ) Fatal error: Class 'B' not found in file2.php on line 2
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Dec 16 07:00:01 2025 UTC |
Please change require("file1.php"); to require("/absolute/path/to/file1.php"); and see if it works.i have changed my code to absolute path. require("F:/LXH/Webs/pware/file2.php"); $k= new B; class B extends A{} the problem is still there. a fatal error was thrown out.require("F:/LXH/Webs/pware/file1.php"); a correction, it was file1.php, not file2.php but im sure the problem is still there.require("file1.php"); $j= new A; $k= new B; class B extends A{} I've changed the code to ensure class A is defined. as shown above, only the line where $k in throws error..do you mean that it's forbidden to write code like within one file: class A{} $j=new B; class B extends A{} or code like: $j=new B; class B{} is also forbidden. But at this moment they all work fine in php. if those mentioned are forbidden, maybe we should write something in the manual to clarify this...