#39567 [Opn->Bgs]: Cannot find Class definition when there is one
| From: | tony2001@php.net | Date: | Tue, 21 Nov 2006 11:33:28 +0000 |
| Subject: | #39567 [Opn->Bgs]: Cannot find Class definition when there is one | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-105245@lists.php.net to get a copy of this message | ||
ID: 39567
Updated by: tony2001@php.net
Reported By: imkow at 163 dot com
-Status: Open
+Status: Bogus
Bug Type: Class/Object related
Operating System: WinXp sp2+Apache2.2+Mod_PHP
PHP Version: 5.2.0
New Comment:
Expected behaviour.
Class "B" cannot be declared in compile time, because class "A" is
declared in another file.
But in runtime, when you execute the line "$obj=new B;", the class "B"
doesn't exist yet.
Previous Comments:
------------------------------------------------------------------------
[2006-11-21 11:26:18] imkow at 163 dot com
require("F:/LXH/Webs/pware/file1.php");
a correction, it was file1.php, not file2.php
but im sure the problem is still there.
------------------------------------------------------------------------
[2006-11-21 11:21:27] imkow at 163 dot com
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.
------------------------------------------------------------------------
[2006-11-21 10:16:07] tony2001@php.net
Please change require("file1.php"); to
require("/absolute/path/to/file1.php"); and see if it works.
------------------------------------------------------------------------
[2006-11-21 09:55:38] imkow at 163 dot com
Description:
------------
Two files:
file1.php:
class A{}
file2.phpF
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.phpF
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
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39567&edit=1