Jump to content

Notice: Undefined variable not sure why.


samtwilliams

Recommended Posts

Can anyone enlighten me as to why i get: Notice: Undefined variable: global_error_reporting in C:\wamp\www\inc\settings.php on line 35.

 

//error handler function
function customError($errno, $errstr)
  {
if ($global_error_reporting == 0) {
} elseif ($global_error_reporting == 1) {

	 $myFile = $www_location."inc\error_log.txt";
	$fh = fopen($myFile, 'a') or die("can't open file"); 
	$stringData = "Error: [$errno] $errstr 
	";
	fwrite($fh, $stringData);
	fclose($fh);
} elseif ($global_error_reporting == 2) {
	echo "<b>Error:</b> [$errno] $errstr";
} elseif ($global_error_reporting == 3) {
	$myFile = $www_location."inc\error_log.txt";
	$fh = fopen($myFile, 'a') or die("can't open file"); 
	$stringData = "Error: [$errno] $errstr 
	";
	fwrite($fh, $stringData);
	fclose($fh);
	echo "<b>Error:</b> [$errno] $errstr";	
}

  }

 

The variable is set further up the page.

 

Thanks

Sam

Link to comment
https://forums.phpfreaks.com/topic/205690-notice-undefined-variable-not-sure-why/
Share on other sites

It means that you haven't actually set a value to it before trying to use the value in a statement.

 

Was this supposed to be a global variable?

 

If yes, you need to tell PHP this.

<?php function customError($errno, $errstr)
{
    global $global_error_reporting; // Tell PHP to look in the global scope rather than local.
    ...
}

 

~juddster

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.