Jump to content

[SOLVED] function is being defined twice but not caught by defined() function.


MadnessRed

Recommended Posts

I have a function which is defined once in one file. it is also safety checked so that the function cannot be defines it is is already defined, yetsomehow it is still being defined twice, from the same file on the same line.

 

Here is the code

<?php
if(defined('ShowLeftMenu')){
echo "<pre>";
print_r(debug_backtrace());
echo "</pre>";
die();
}else{
function ShowLeftMenu ( $Level, $Template = 'left_menu' ) { //Line 8
	//The function goes here but is ommited coz it is large and not needed.
}
}
?>

 

However I get the following error

 

Fatal error: Cannot redeclare showleftmenu() (previously declared in /var/www/leftmenu.php:8) in /var/www/leftmenu.php on line 8

 

I do not get a debug backtrace() being outputted either, this one has really confused me as I don't how it is possible for that function to even be considered it it is already defined as the if statement should filter it out.

 

To see how many times the code was run I changed the code to this.

<?php
if(defined('ShowLeftMenu')){
echo "Called and failed";
echo "<pre>";
print_r(debug_backtrace());
echo "</pre>";
die();
}else{
echo "Called and success";
function ShowLeftMenu ( $Level, $Template = 'left_menu' ) {

Here is the output

Called and successCalled and success

 

So clearly there is something wrong with the defined(). Any help would be great.

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.