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
https://forums.phpfreaks.com/topic/58252-classes-with-same-name-error/
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

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...

http://bugs.php.net/report.php

 

I would suggest reporting the bug if you cannot find it already being reported. But know that it could also be your configuration of apache or iis or even php. Test it in Firefox too just to see what happens, as thorpe said it could be a browser issue.

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

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.