Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Script Help Required: Undefined Variable, A fault I cannot spot in PHP
mrdee
post Jan 25 2008, 01:52 AM
Post #1


Super Member
*********

Group: [HOSTED]
Posts: 248
Joined: 18-July 07
From: Slough (UK)
Member No.: 46,682



Hi, when running a PHP script I keep getting the error:
QUOTE
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:
CODE
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.

Go to the top of the page
 
+Quote Post
truefusion
post Jan 25 2008, 12:07 PM
Post #2


Ephesians 6:10-17
Group Icon

Group: [MODERATOR]
Posts: 1,833
Joined: 22-June 05
From: The place where moving forward means moving backwards.
Member No.: 8,528
T17 GFX Crew



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:
CODE
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.
Go to the top of the page
 
+Quote Post
DarAngel
post Feb 8 2008, 11:51 AM
Post #3


Newbie
*

Group: Members
Posts: 1
Joined: 8-February 08
Member No.: 57,551



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:

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

This post has been edited by DarAngel: Feb 8 2008, 12:11 PM
Go to the top of the page
 
+Quote Post
dave2win
post Apr 8 2008, 05:25 AM
Post #4


Member [Level 1]
****

Group: [HOSTED]
Posts: 65
Joined: 7-April 08
From: Toronto, Canada
Member No.: 60,502



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

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



indtead of

CODE
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

Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Script: Php Jukebox(4)
  2. Parse: Error Unexpected T_lnumber(4)
  3. Transfer Variables To Another Php Script(8)
  4. Watermark Your Image With Simple Php Script(33)
  5. Script That Tracks The User Status(4)
  6. Wappychat_oldskool(15)
  7. Php Search Engine Script For Mysql Database(11)
  8. Free Auction Script(6)
  9. Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig(3)
  10. What Kind Of Script Do You Need ?(15)
  11. Creatting A Playlist Through Php(5)
  12. Is This A Good Script?(9)
  13. Getting An Array Value Of A Dynamic Variable(9)
  14. Html Code Tester. Online Script(15)
  15. Making Sure They Did Not Leave Any Required Fields Blank(3)
  1. Php Sessions And Post Variables Issues(1)
  2. Will This Code Work(5)
  3. Php Downloads Script(3)
  4. Script Not Working(6)
  5. Library Script(6)
  6. How Would I Go About Making A Simple "counting" Script?(3)
  7. Forum Script(3)
  8. Php Rediret Script(12)
  9. Download Script For Mp3 Files(0)
  10. How Do I Connect To Live Database With Php Script?(6)
  11. Need Help Installing Dolphin Community Script!(5)
  12. Unexpected T_variable...(3)
  13. Guessing Php Script(0)


 



- Lo-Fi Version Time is now: 4th July 2008 - 10:51 PM