Jump to content
xisto Community
mrdee

Script Help Required: Undefined Variable A fault I cannot spot in PHP

Recommended Posts

Hi, when running a PHP script I keep getting the error:

Notice: Undefined variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294
Notice: Undefined variable: bret in c:\program files\easyphp1-8\home\poll.php on line 294

(And, yes, I get it twice).

The code related to the variable is as follows:
function LogString($string,$type)	{		$t_log = "\n";		$t_log .= $this->globaldata->server_vars['REMOTE_ADDR']."|";				$t_log .= date("Y-m-d h:i:s A|");		$t_log .= "$type| ";		$string = str_replace("\n","\\n",$string);				$t_log .= $string;		if($this->is_enabled)		{			$bret = $this->writeToFile($t_log);		}		$this->whole_log .= $t_log;		return $bret;	}

I must stress that I did not write this code myself, but a program called 'Simfatic Forms' which I am Beta testing.

Can anyone spot where the mistake might be?
Thanks for any help I might get.

Share this post


Link to post
Share on other sites

I'm assuming $this->is_enabled is returning false. Since it's returning false, the bret variable will not be set. My only suggestion is to make the if statement have an else:

if($this->is_enabled){$bret = $this->writeToFile($t_log);} else {$bret = FALSE;}
And the only reason i can think of why the error appears twice is because the function LogString is be-ing called twice.

 

I say all of this bearing ignorance of the rest of the script.

Share this post


Link to post
Share on other sites

Yes as what the truefusion said I think that the script is reporting a notice that the String is null you can set the error reporting to:

error_reporting(E_ALL ^ E_NOTICE);

(add near the beginning of the script)

This way you can continue to have the empty sting but you won't be told about it, I think that Notices shouldn't effect the functionality of your scripts. (I have notices turned off by default in my local PHP server environment)

With the code the truefusion posted you can also clear the notice (I believe.) It all depends on your preference.
Edited by DarAngel (see edit history)

Share this post


Link to post
Share on other sites

This is for Dar Angel


If the guy mrdee is Beta testing some thing then he should not turn Error Reporting off. This will keep the errors hidden and the program will come out as a faulty program. Beta Tersting should be always be done with Error Reporting settings changed to all.


And for your problem (@mrdee)


The function is returning $bret without checking it's existance.
Just do a check if it's set or not using.

Try & use this code::::

if(isset($bret)){return $bret;}


indtead of

return $bret;


I think it error is being given twice because the function is being called twice by some other func.


This is all that i could think of.


Dave

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.