|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39294 "Fatal error: Cannot redeclare class" for classes that use extends
Submitted: 2006-10-28 23:39 UTC Modified: 2006-10-29 00:02 UTC
From: a79315 at hotmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.2 OS: suse 10.1
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: a79315 at hotmail dot com
New email:
PHP Version: OS:


 [2006-10-28 23:39 UTC] a79315 at hotmail dot com
This code works fine on PHP 4 but fails on PHP 5.1.2. I know that I need to try it on the 5.1.6 version but I can't get my suse server to upgrade to it. On PHP 5.1.2 it reports "Fatal error: Cannot redeclare class". If the "extends CTest3" is removed from file there is no error.

Reproduce code:
File 1: test.php
require "";
require "";

File 2:

if (defined("CTEST2")) return;
define("CTEST2", 1);

require "";

class CTest2 extends CTest3

function CTest2()
	print "Test2";



File 3: ?

if (defined("CTEST3")) return;
define("CTEST3", 1);

class CTest3

function CTest3()
	print "Test3";



Expected result:
No error

Actual result:
Fatal error: Cannot redeclare class ctest2 in on line 16


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-28 23:46 UTC] a79315 at hotmail dot com
Should read: If
the "extends CTest3" is removed from file there is no error.
 [2006-10-29 00:02 UTC]
>if (defined("CTEST2")) return;
>define("CTEST2", 1);

Classes are declared at compile time, while 'if() return;' is executed at runtime, so this is 100% expected behaviour.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 07:01:29 2024 UTC