Jump to content

Classes with same name error


eric1235711

Recommended Posts

Hello,

 

I lost some time trying to find out a problem: when I included a file in my script, it showed a "Page not found" error.

 

I discovered that the file I was including had another version of a class that is already set in my "common header include".

 

well, my doubt is:

 

"Why PHP didn't say that there were classes with the same name???"

 

thanks in advance!

Link to comment
Share on other sites

error_reporting(E_ALL & ~E_NOTICE);

 

the problem is that it shows the browser's "page not found" error message...

 

try reproducing the error:

 

create two files with

class test{
	function __construct(){
			echo "ok";
	}
}

you can change the methods and properties.

and then include both in another file, or make one file include the other.

 

Boom! "Page Not Found" LOL

Link to comment
Share on other sites

If I could try it I would, but no PHP on this box.

 

Why are you including two classes of the same name anyways, that should at least throw an error. Maybe it is a bug in PHP5. I think PHP 4 would throw an error.

 

If someone else has PHP 5 and wants to confirm it I Would suggest submitting a bug report. But either way you shouldn't have two classes named the same and included at the same time...

Link to comment
Share on other sites

Have you enabled display_errors? display_errors is turned off by defualt. If it is not enabled no errors will be shown during runtime. Turn display_errors on and it should display errors.

 

Get the following error:

Fatal error: Cannot redeclare class test in C:\Server\www\class.test.php on line 3

 

I did what you suggested to do for reproducing the error. class.test.php is the file that has the same class code as the file that is including class.test.php

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.