Re: [PHP] Undefined Variables

2013-02-14 Thread Ashley Sheridan


Roman Gelfand rgelfa...@gmail.com wrote:

Is there a performance hit when a variable is undefined? or, perhaps,
aside from the obvious uncontrolled conditions, are there other
impacts?

Thanks in advance

Aside from all the warnings and potential logic bombs?

You will have a negligible performance hit with all the isset() checks you'll 
be using, but they won't be noticeable, and its preferred to use them than not 
to avoid issues with missing values.
Thanks,
Ash
http://www.ashleysheridan.co.uk

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Undefined Variables

2013-02-14 Thread Matijn Woudt
On Thu, Feb 14, 2013 at 7:04 PM, Roman Gelfand rgelfa...@gmail.com wrote:

 Is there a performance hit when a variable is undefined? or, perhaps,
 aside from the obvious uncontrolled conditions, are there other
 impacts?

 Thanks in advance


There might be a little performance hit because the error is getting logged
in your webservers logs, though if it is noticeable depends on which
webserver you're using, and how often there are undefined variables.

- Matijn


Re: [PHP] Undefined Variables

2013-02-14 Thread Jan Ehrhardt
Matijn Woudt in php.general (Thu, 14 Feb 2013 19:12:55 +0100):
On Thu, Feb 14, 2013 at 7:04 PM, Roman Gelfand rgelfa...@gmail.com wrote:

 Is there a performance hit when a variable is undefined? or, perhaps,
 aside from the obvious uncontrolled conditions, are there other
 impacts?

There might be a little performance hit because the error is getting logged
in your webservers logs, though if it is noticeable depends on which
webserver you're using, and how often there are undefined variables.

And frameworks like Drupal might intercept the error and store it in the
watchdog file. Then the performance will be degraded.

Jan

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Undefined Variables

2013-02-14 Thread Stuart Dallas
Sorry for the top post!

I don't know numbers, but my gut instinct is that the cycles wasted raising the 
notice (it gets raised even if it goes nowhere so turning display and log 
doesn't remove the hit completely) are better spent executing defensive code.

There is no reason, ever, that production code should raise notices about which 
you don't care. If PHP is telling you something might be wrong, something might 
be wrong! And if you're investigating the code already, figure out what's 
happening and deal with it properly.

Only lazy and/or developers ignore notices. If you're one of them and this 
statement offends you, you probably know it's right!

-Stuart

-- 
Sent from my leaf blower

On 14 Feb 2013, at 18:04, Roman Gelfand rgelfa...@gmail.com wrote:

 Is there a performance hit when a variable is undefined? or, perhaps,
 aside from the obvious uncontrolled conditions, are there other
 impacts?
 
 Thanks in advance
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Undefined Variables

2013-02-14 Thread Al



On 2/14/2013 1:54 PM, Stuart Dallas wrote:

Sorry for the top post!

I don't know numbers, but my gut instinct is that the cycles wasted raising the 
notice (it gets raised even if it goes nowhere so turning display and log 
doesn't remove the hit completely) are better spent executing defensive code.

There is no reason, ever, that production code should raise notices about which 
you don't care. If PHP is telling you something might be wrong, something might 
be wrong! And if you're investigating the code already, figure out what's 
happening and deal with it properly.

Only lazy and/or developers ignore notices. If you're one of them and this 
statement offends you, you probably know it's right!

-Stuart



I agree with Stuart.

To minimize the overhead of testing every possible undefined variable with 
isset(), I assign them at the top of the page which uses them. e.g.,


$userInstrHtmlSizeWarning = false;
$currentUserRecArray = array();
if(!isset($_SESSION['pwPassed']))$_SESSION['pwPassed'] = false;

I also have this snippet at the top of my app config file.

if(true){ // TRUE for debug only
  ini_set(display_errors, on); //use off if users will see them
  error_reporting(E_ALL)
  $error_reporting = 'span style=color:redError display and logging 
on/span  ';

}
else $error_reporting=null;

I put this at a convenient place on the page so I don't forget to turn off the 
error reporting when the code goes live.


if($error_reporting) echo $error_reporting;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Undefined Variables

2013-02-14 Thread Stuart Dallas
On 14 Feb 2013, at 20:57, Al n...@ridersite.org wrote:
 On 2/14/2013 1:54 PM, Stuart Dallas wrote:
 Sorry for the top post!
 
 I don't know numbers, but my gut instinct is that the cycles wasted raising 
 the notice (it gets raised even if it goes nowhere so turning display and 
 log doesn't remove the hit completely) are better spent executing defensive 
 code.
 
 There is no reason, ever, that production code should raise notices about 
 which you don't care. If PHP is telling you something might be wrong, 
 something might be wrong! And if you're investigating the code already, 
 figure out what's happening and deal with it properly.
 
 Only lazy and/or developers ignore notices. If you're one of them and this 
 statement offends you, you probably know it's right!
 
 -Stuart
 
 
 I agree with Stuart.
 
 To minimize the overhead of testing every possible undefined variable with 
 isset(), I assign them at the top of the page which uses them. e.g.,
 
 $userInstrHtmlSizeWarning = false;
 $currentUserRecArray = array();
 if(!isset($_SESSION['pwPassed']))$_SESSION['pwPassed'] = false;
 
 I also have this snippet at the top of my app config file.
 
 if(true){ // TRUE for debug only
  ini_set(display_errors, on); //use off if users will see them
  error_reporting(E_ALL)
  $error_reporting = 'span style=color:redError display and logging 
 on/span  ';
 }
 else $error_reporting=null;
 
 I put this at a convenient place on the page so I don't forget to turn off 
 the error reporting when the code goes live.
 
 if($error_reporting) echo $error_reporting;

I've used the following method for accessing elements of the global arrays for 
a long time. It saves a lot of typing!

http://stut.net/2011/04/12/php-snippet-array-element-access/

Note that if you're using PHP5 you should remove the  before the $a in the 
function definition.

-Stuart

-- 
Stuart Dallas
3ft9 Ltd
http://3ft9.com/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Undefined variables?

2002-11-18 Thread Ernest E Vogelsinger
At 15:57 18.11.2002, Martin Magnusson spoke out and said:
[snip]
I installed php 4.2.3 on Apache2.

When I write ? echo $anyvariable; ? I get an error message telling me that
I have an undefined variable $anyvariable. Is this something new that one
must declare all variables?

In my previous version of php the expression above would return an empty
string - no error messages...
[snip] 

This is defined by the setting of error_reporting in your php.ini file.
What you get is not an error but a notice message that you are using an
undefined variable.

This can be handy if you want to spot the error when your script doesn't
behave like it should... anyway, to turn it off:

- in php.ini:
  error_reporting = E_ALL  ~E_NOTICE

- in your script:
  error_reporting(E_ALL  ~E_NOTICE);

- avoiding this:
  if (isset($anyvariable)) echo $anyvariable;


-- 
   O Ernest E. Vogelsinger 
   (\) ICQ #13394035 
^ http://www.vogelsinger.at/



Re: [PHP] Undefined variables?

2002-11-18 Thread Maxim Maletsky

set error reporting to 55


--
Maxim Maletsky
[EMAIL PROTECTED]



Martin Magnusson [EMAIL PROTECTED] wrote... :

 I installed php 4.2.3 on Apache2.
 
 When I write ? echo $anyvariable; ? I get an error message telling me that
 I have an undefined variable $anyvariable. Is this something new that one
 must declare all variables?
 
 In my previous version of php the expression above would return an empty
 string - no error messages...
 
 Hope you understand my problem...
 
 Martin Magnusson
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables?

2002-10-10 Thread Marco Tabini

Of course, you should switch to UNIX :-)

Seriously, have you looked at the source on those lines? Can you post
the source code otherwise so we can take a look and let you know?

The error you are receiving usually means that a variable is used
without having been initialized. For example:

$b = $a * 10;

Will cause a warning if $a is not set to something.


Marco

On Thu, 2002-10-10 at 16:07, Justoman wrote:
 I get this with almost all the scripts I run,
 
 It's a whole shit load of undefined variables! what are these and please,
 how can they be fixed?
 
 Here's what I'm talkin bout,
 http://www.darkwatchclan.com/battlestats/bfserverinfo.php
 
 -Justoman
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables?

2002-10-10 Thread Justoman


Thanks for the feedback,
I've never actually posted here, so Kevin, cut me some slack.

Here's whats up,
The script I'm trying to run is called Battlestats
It's set up on at: http://www.darkwatchclan.com/battlestats/bfserverinfo.php
(That's where I'm trying to get it to work)

Now, the exact same unedited scipt has been set up on,
http://jk2.gamersimpact.com/bf1942/bfserverinfo.php and runs perfectly.

The source for it, could be found with this link:
http://jk2.gamersimpact.com/download.php?op=getitlid=3

So really, its not so much a programmer error, it just has something to do
with either an error concerning OS working with script, or something wrong
with the PHP that's set up on the server, because this isn't the only
working script that doesn't parse properly on this server. All the errors I
get are undefined variables.

-Justin Justoman Antolini



Kevin Stone [EMAIL PROTECTED] wrote in message
005701c2709c$b651d2e0$6501a8c0@kevin">news:005701c2709c$b651d2e0$6501a8c0@kevin...
 Not to be rude.. but you have got to be kidding.  :-\

 There's no way for anybody to tell what's going on without seeing the
code.
 One way or another the script isn't being given the information it is
 expecting.  My guess is that the programmer isn't doing any checking
within
 the script.  He's assuming that these values are set but when they're not
it
 spews this list of errors.

 Is this a script that you wrote or are you here on behalf of the
programmer?

 -Kevin

 - Original Message -
 From: Justoman [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, October 10, 2002 2:07 PM
 Subject: [PHP] Undefined variables?


  I get this with almost all the scripts I run,
 
  It's a whole shit load of undefined variables! what are these and
please,
  how can they be fixed?
 
  Here's what I'm talkin bout,
  http://www.darkwatchclan.com/battlestats/bfserverinfo.php
 
  -Justoman
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables?

2002-10-10 Thread Marco Tabini

I think the problem is simply that the other server had a different
configuration setting for error reporting, since I can't find
$debug_wintrmte configured anywhere.

I don't know what this code is for, so it's difficult for me to say how
to fix it, since any changes I make may affect the outcome in a way that
will cause the system to stop working properly.

The only suggestion is to contact the original author or (if you are the
original author) to figure out how those variables should be managed. As
a last resort, and only if you are satisfied with the way the site works
right now (aside from the errors, of course), as James Hicks was
suggesting, you can just hide the errors by typing 

error_reporting(0); 

on the second line of the file, right after the ?

Hope this helps

On Thu, 2002-10-10 at 16:56, Justoman wrote:
 
 Thanks for the feedback,
 I've never actually posted here, so Kevin, cut me some slack.
 
 Here's whats up,
 The script I'm trying to run is called Battlestats
 It's set up on at: http://www.darkwatchclan.com/battlestats/bfserverinfo.php
 (That's where I'm trying to get it to work)
 
 Now, the exact same unedited scipt has been set up on,
 http://jk2.gamersimpact.com/bf1942/bfserverinfo.php and runs perfectly.
 
 The source for it, could be found with this link:
 http://jk2.gamersimpact.com/download.php?op=getitlid=3
 
 So really, its not so much a programmer error, it just has something to do
 with either an error concerning OS working with script, or something wrong
 with the PHP that's set up on the server, because this isn't the only
 working script that doesn't parse properly on this server. All the errors I
 get are undefined variables.
 
 -Justin Justoman Antolini
 
 
 
 Kevin Stone [EMAIL PROTECTED] wrote in message
 005701c2709c$b651d2e0$6501a8c0@kevin">news:005701c2709c$b651d2e0$6501a8c0@kevin...
  Not to be rude.. but you have got to be kidding.  :-\
 
  There's no way for anybody to tell what's going on without seeing the
 code.
  One way or another the script isn't being given the information it is
  expecting.  My guess is that the programmer isn't doing any checking
 within
  the script.  He's assuming that these values are set but when they're not
 it
  spews this list of errors.
 
  Is this a script that you wrote or are you here on behalf of the
 programmer?
 
  -Kevin
 
  - Original Message -
  From: Justoman [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Thursday, October 10, 2002 2:07 PM
  Subject: [PHP] Undefined variables?
 
 
   I get this with almost all the scripts I run,
  
   It's a whole shit load of undefined variables! what are these and
 please,
   how can they be fixed?
  
   Here's what I'm talkin bout,
   http://www.darkwatchclan.com/battlestats/bfserverinfo.php
  
   -Justoman
  
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 
 
 
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-05-31 Thread Philip Olson


Another similar way, using an array (very simple to 
add tasks):

  $tasks = array('ShowVersion','GetData','CreateImage');

  if (@in_array($_REQUEST['Task'], $tasks)) {
  // add some error checking here (function_exists())
  $$Task();
  } else {
  // maybe run a default task here
  print unknown task;
  }

Am using @ in case 'Task' doesn't exist at all, so no 
error will be seen (undefined variables create E_NOTICE 
level errors).  Although you may want to check this before 
Task even reaches in_array(), with empty().  See also:

  http://www.php.net/error_reporting

$$Task() is a variable function:

  http://uk.php.net/manual/functions.variable-functions.php

And $_REQUEST is a PHP predefined/reserved variable that 
contains a mix of Get, Post and Cookie data.  This may or 
may not be appropriate here:
 
  http://au.phpz.net/manual/language.variables.predefined.php

On a sidenote (picky), consider making variables all 
lowercase. Also when printing a single var, no need to 
surround it with quotes.  print $foo.

Regards,
Philip Olson

On Fri, 31 May 2002, Christopher J. Crane wrote:

 I like this piece of code. In fact, I convert all my scripts that use the
 older If/Else  code. What would happen if the break;  wasn't used. Would
 it just continue through the rest of the function to find another match???
 
 Miguel Cruz [EMAIL PROTECTED] wrote in message
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  On Thu, 30 May 2002, Crane, Christopher wrote:
   if ($Task == ShowVersion) { function ShowVersion(); }
   elseif ($Task == GetData) { function GetData(); print $DataOutput; }
   elseif ($Task == CreateImage) { function CreateImage(); }
   else { print Incorrect Variable or no Variable Suppliesbr; }
 
  if (isset($Task))
  {
switch($Task)
{
case 'ShowVersion':
  ShowVersion();
  break;
case 'GetData':
  GetData;
  print $DataOutput;
  break;
case 'CreateImage':
  CreateImage();
  break;
default:
  print 'Unknown function';
}
  } else {
print 'No function supplied';
  }
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Undefined variables

2002-05-31 Thread Darren Gamble

Good day,

I don't have a piece of code off the top of my head, but you'll get lots of
results and examples if you enter those variables into www.php.net 's search
field and search the online documentation (which is very, very good, I
should add).

Hope that helps.


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


 -Original Message-
 From: Christopher J. Crane [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, May 30, 2002 8:06 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] Undefined variables
 
 
 Darren,
 Thanks for the tip on direction to head in. Could you provide 
 an example of
 what you are referring to?
 
 
 Darren Gamble [EMAIL PROTECTED] wrote in message
 078EC26E265CD411BD9100508BDFFC860ED3E64E@shawmail02">news:078EC26E265CD411BD9100508BDFFC860ED3E64E@shawmail02...
  Good day,
 
  Just to clarify, Perl will, in fact, complain if you have undefined
  variables (or variables that you use once) if you have 
 warnings and/or
  strict mode in effect.  Using at least one is strongly recommended.
 
  In PHP, the method you're using for getting form data is 
 deprecated.  You
  should use $HTTP_POST_VARS or $_POST, depending on your 
 version.  Check
 the
  docco for more info on those.
 
  If you really have to check variables using this method, 
 use isset() to
 see
  if the variables ... have been set. =)
 
  
  Darren Gamble
  Planner, Regional Services
  Shaw Cablesystems GP
  630 - 3rd Avenue SW
  Calgary, Alberta, Canada
  T2P 4L4
  (403) 781-4948
 
 
   -Original Message-
   From: Crane, Christopher [mailto:[EMAIL PROTECTED]]
   Sent: Thursday, May 30, 2002 3:07 PM
   To: '[EMAIL PROTECTED]'
   Subject: [PHP] Undefined variables
  
  
   I have an annoying problem, that I know is my own ignorance
   to PHP. I came
   from PERL and this was not a problem there but is with PHP.
  
   Here's the issue.
   I have a number of scripts that use a index.php?Task='some
   sort of task
   name', for example, http://www.foo.com/index.php?Task=ShowVersion
   http://www.foo.com/index.php?Task=ShowVersion .  Then I use
   an if/else
   statement to tell the script what to do if it sees the
   ShowVersion variable.
   In the ShowVersion example, I would call a function that 
 displays the
   version information I defined in the script. As a back up, I
   always provide
   an else statement to catch variables I have no functions for.
  
   If I have a ShowVersion function, GetData function and a 
 CreateImage
   function and the Task variable is empty or a variable that
   does not exists
   comes in like http://www.foo.com/index.php?Task=SomethingDumb
   http://www.foo.com/index.php?Task=SomethingDumb  it 
 would go to the
   default function of something by using the ELSE part of 
 the if/else
   statements.
  
   I hope I am describing this correctly.now here is the
   problem. If I have
   warnings turned on, or if I have a log written for warnings,
   the log fills
   up if someone goes to http://www.foo.com/index.php
   http://www.foo.com/index.php  or http://www.foo.com
  http://www.foo.com
  will error messages like undefine variable TASK on line 
 255. I understand
  the reason, that PHP was expecting the variable Task when 
 it got to the
  if/else statements. So I put in something like if(!($Task)) 
 { function
  Something(); } but it still is looking for the variable so it still
 errors.
 
  In Perl, it would simply be ignored. What do I do here.
 
  Here is a simple example of the code.
 
  if ($Task == ShowVersion) { function ShowVersion(); }
  elseif ($Task == GetData) { function GetData(); print 
 $DataOutput; }
  elseif ($Task == CreateImage) { function CreateImage(); }
  else { print Incorrect Variable or no Variable Suppliesbr; }
 
 
 
 
 
  Christopher J. Crane
  Network Operations Manager
 
  IKON Office Solutions
  860.659.6464
 
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Undefined variables

2002-05-30 Thread Leotta, Natalie (NCI/IMS)

You could try using isset first.  I'm not sure where your log is, but if you
check to see if task is set, then maybe that will eliminate the problem :-)

-Natalie

http://www.php.net/manual/en/function.isset.php

-Original Message-
From: Crane, Christopher [mailto:[EMAIL PROTECTED]] 
Sent: Thursday, May 30, 2002 5:07 PM
To: '[EMAIL PROTECTED]'
Subject: [PHP] Undefined variables


I have an annoying problem, that I know is my own ignorance to PHP. I came
from PERL and this was not a problem there but is with PHP.
 
Here's the issue.
I have a number of scripts that use a index.php?Task='some sort of task
name', for example, http://www.foo.com/index.php?Task=ShowVersion
http://www.foo.com/index.php?Task=ShowVersion .  Then I use an if/else
statement to tell the script what to do if it sees the ShowVersion variable.
In the ShowVersion example, I would call a function that displays the
version information I defined in the script. As a back up, I always provide
an else statement to catch variables I have no functions for.
 
If I have a ShowVersion function, GetData function and a CreateImage
function and the Task variable is empty or a variable that does not exists
comes in like http://www.foo.com/index.php?Task=SomethingDumb
http://www.foo.com/index.php?Task=SomethingDumb  it would go to the
default function of something by using the ELSE part of the if/else
statements. 
 
I hope I am describing this correctly.now here is the problem. If I have
warnings turned on, or if I have a log written for warnings, the log fills
up if someone goes to http://www.foo.com/index.php
http://www.foo.com/index.php  or http://www.foo.com http://www.foo.com
will error messages like undefine variable TASK on line 255. I understand
the reason, that PHP was expecting the variable Task when it got to the
if/else statements. So I put in something like if(!($Task)) { function
Something(); } but it still is looking for the variable so it still errors.
 
In Perl, it would simply be ignored. What do I do here.
 
Here is a simple example of the code.
 
if ($Task == ShowVersion) { function ShowVersion(); }
elseif ($Task == GetData) { function GetData(); print $DataOutput; }
elseif ($Task == CreateImage) { function CreateImage(); } else { print
Incorrect Variable or no Variable Suppliesbr; }
 
 
 
 

Christopher J. Crane
Network Operations Manager

IKON Office Solutions
860.659.6464

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Undefined variables

2002-05-30 Thread Darren Gamble

Good day,

Just to clarify, Perl will, in fact, complain if you have undefined
variables (or variables that you use once) if you have warnings and/or
strict mode in effect.  Using at least one is strongly recommended.

In PHP, the method you're using for getting form data is deprecated.  You
should use $HTTP_POST_VARS or $_POST, depending on your version.  Check the
docco for more info on those.

If you really have to check variables using this method, use isset() to see
if the variables ... have been set. =)


Darren Gamble
Planner, Regional Services
Shaw Cablesystems GP
630 - 3rd Avenue SW
Calgary, Alberta, Canada
T2P 4L4
(403) 781-4948


 -Original Message-
 From: Crane, Christopher [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, May 30, 2002 3:07 PM
 To: '[EMAIL PROTECTED]'
 Subject: [PHP] Undefined variables
 
 
 I have an annoying problem, that I know is my own ignorance 
 to PHP. I came
 from PERL and this was not a problem there but is with PHP.
  
 Here's the issue.
 I have a number of scripts that use a index.php?Task='some 
 sort of task
 name', for example, http://www.foo.com/index.php?Task=ShowVersion
 http://www.foo.com/index.php?Task=ShowVersion .  Then I use 
 an if/else
 statement to tell the script what to do if it sees the 
 ShowVersion variable.
 In the ShowVersion example, I would call a function that displays the
 version information I defined in the script. As a back up, I 
 always provide
 an else statement to catch variables I have no functions for.
  
 If I have a ShowVersion function, GetData function and a CreateImage
 function and the Task variable is empty or a variable that 
 does not exists
 comes in like http://www.foo.com/index.php?Task=SomethingDumb
 http://www.foo.com/index.php?Task=SomethingDumb  it would go to the
 default function of something by using the ELSE part of the if/else
 statements. 
  
 I hope I am describing this correctly.now here is the 
 problem. If I have
 warnings turned on, or if I have a log written for warnings, 
 the log fills
 up if someone goes to http://www.foo.com/index.php
 http://www.foo.com/index.php  or http://www.foo.com 
http://www.foo.com
will error messages like undefine variable TASK on line 255. I understand
the reason, that PHP was expecting the variable Task when it got to the
if/else statements. So I put in something like if(!($Task)) { function
Something(); } but it still is looking for the variable so it still errors.
 
In Perl, it would simply be ignored. What do I do here.
 
Here is a simple example of the code.
 
if ($Task == ShowVersion) { function ShowVersion(); }
elseif ($Task == GetData) { function GetData(); print $DataOutput; }
elseif ($Task == CreateImage) { function CreateImage(); }
else { print Incorrect Variable or no Variable Suppliesbr; }
 
 
 
 

Christopher J. Crane
Network Operations Manager

IKON Office Solutions
860.659.6464

 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-05-30 Thread Christopher J. Crane

Darren,
Thanks for the tip on direction to head in. Could you provide an example of
what you are referring to?


Darren Gamble [EMAIL PROTECTED] wrote in message
078EC26E265CD411BD9100508BDFFC860ED3E64E@shawmail02">news:078EC26E265CD411BD9100508BDFFC860ED3E64E@shawmail02...
 Good day,

 Just to clarify, Perl will, in fact, complain if you have undefined
 variables (or variables that you use once) if you have warnings and/or
 strict mode in effect.  Using at least one is strongly recommended.

 In PHP, the method you're using for getting form data is deprecated.  You
 should use $HTTP_POST_VARS or $_POST, depending on your version.  Check
the
 docco for more info on those.

 If you really have to check variables using this method, use isset() to
see
 if the variables ... have been set. =)

 
 Darren Gamble
 Planner, Regional Services
 Shaw Cablesystems GP
 630 - 3rd Avenue SW
 Calgary, Alberta, Canada
 T2P 4L4
 (403) 781-4948


  -Original Message-
  From: Crane, Christopher [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, May 30, 2002 3:07 PM
  To: '[EMAIL PROTECTED]'
  Subject: [PHP] Undefined variables
 
 
  I have an annoying problem, that I know is my own ignorance
  to PHP. I came
  from PERL and this was not a problem there but is with PHP.
 
  Here's the issue.
  I have a number of scripts that use a index.php?Task='some
  sort of task
  name', for example, http://www.foo.com/index.php?Task=ShowVersion
  http://www.foo.com/index.php?Task=ShowVersion .  Then I use
  an if/else
  statement to tell the script what to do if it sees the
  ShowVersion variable.
  In the ShowVersion example, I would call a function that displays the
  version information I defined in the script. As a back up, I
  always provide
  an else statement to catch variables I have no functions for.
 
  If I have a ShowVersion function, GetData function and a CreateImage
  function and the Task variable is empty or a variable that
  does not exists
  comes in like http://www.foo.com/index.php?Task=SomethingDumb
  http://www.foo.com/index.php?Task=SomethingDumb  it would go to the
  default function of something by using the ELSE part of the if/else
  statements.
 
  I hope I am describing this correctly.now here is the
  problem. If I have
  warnings turned on, or if I have a log written for warnings,
  the log fills
  up if someone goes to http://www.foo.com/index.php
  http://www.foo.com/index.php  or http://www.foo.com
 http://www.foo.com
 will error messages like undefine variable TASK on line 255. I understand
 the reason, that PHP was expecting the variable Task when it got to the
 if/else statements. So I put in something like if(!($Task)) { function
 Something(); } but it still is looking for the variable so it still
errors.

 In Perl, it would simply be ignored. What do I do here.

 Here is a simple example of the code.

 if ($Task == ShowVersion) { function ShowVersion(); }
 elseif ($Task == GetData) { function GetData(); print $DataOutput; }
 elseif ($Task == CreateImage) { function CreateImage(); }
 else { print Incorrect Variable or no Variable Suppliesbr; }





 Christopher J. Crane
 Network Operations Manager

 IKON Office Solutions
 860.659.6464





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-05-30 Thread Miguel Cruz

On Thu, 30 May 2002, Crane, Christopher wrote:
 if ($Task == ShowVersion) { function ShowVersion(); }
 elseif ($Task == GetData) { function GetData(); print $DataOutput; }
 elseif ($Task == CreateImage) { function CreateImage(); }
 else { print Incorrect Variable or no Variable Suppliesbr; }

if (isset($Task))
{
  switch($Task)
  {
  case 'ShowVersion':
ShowVersion();
break;
  case 'GetData':
GetData;
print $DataOutput;
break;
  case 'CreateImage':
CreateImage();
break;
  default:
print 'Unknown function';
  }
} else {
  print 'No function supplied';
}



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-05-30 Thread Christopher J. Crane

I like this piece of code. In fact, I convert all my scripts that use the
older If/Else  code. What would happen if the break;  wasn't used. Would
it just continue through the rest of the function to find another match???

Miguel Cruz [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Thu, 30 May 2002, Crane, Christopher wrote:
  if ($Task == ShowVersion) { function ShowVersion(); }
  elseif ($Task == GetData) { function GetData(); print $DataOutput; }
  elseif ($Task == CreateImage) { function CreateImage(); }
  else { print Incorrect Variable or no Variable Suppliesbr; }

 if (isset($Task))
 {
   switch($Task)
   {
   case 'ShowVersion':
 ShowVersion();
 break;
   case 'GetData':
 GetData;
 print $DataOutput;
 break;
   case 'CreateImage':
 CreateImage();
 break;
   default:
 print 'Unknown function';
   }
 } else {
   print 'No function supplied';
 }





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Undefined variables

2002-05-30 Thread Martin Towell

if you want to do the same thing for no task supplied and unknown task
then you could do this:

switch(@$Task)
{
  case 'ShowVersion':
ShowVersion();
break;
  case 'GetData':
GetData;
print $DataOutput;
break;
  case 'CreateImage':
CreateImage();
break;
  default:
print 'Unknown function or No function supplied';
}

basically, suppress warnings

-Original Message-
From: Christopher J. Crane [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 2:33 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Undefined variables


I like this piece of code. In fact, I convert all my scripts that use the
older If/Else  code. What would happen if the break;  wasn't used. Would
it just continue through the rest of the function to find another match???

Miguel Cruz [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 On Thu, 30 May 2002, Crane, Christopher wrote:
  if ($Task == ShowVersion) { function ShowVersion(); }
  elseif ($Task == GetData) { function GetData(); print $DataOutput; }
  elseif ($Task == CreateImage) { function CreateImage(); }
  else { print Incorrect Variable or no Variable Suppliesbr; }

 if (isset($Task))
 {
   switch($Task)
   {
   case 'ShowVersion':
 ShowVersion();
 break;
   case 'GetData':
 GetData;
 print $DataOutput;
 break;
   case 'CreateImage':
 CreateImage();
 break;
   default:
 print 'Unknown function';
   }
 } else {
   print 'No function supplied';
 }





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-03-30 Thread Lars Torben Wilson

On Sat, 2002-03-30 at 17:30, Ernesto wrote:
 Hi, newbie here.
 
 I was erroneously using error_reporting=E_ALL ~E_NOTICE on my debug
 server.
 Now, I changed it to error_reporting=E_ALL and I can see lots of warnings
 about using undefined variables.
 So, if I don't want to see warnings all over the place, I have to check
 every variable with isset() before I use it.
 Is it necesary that I do this all the time? Why can't I trust on the
 emptiness of uninitialized variables?
 I'm using register_globals=Off, so there should be no problem with that.
 
 I know it's a good practice to declare and initialize all variables, but I
 need my scripts to run as fast as they can (and I'm too lazy to check every
 variable before I use it, too :-)
 
 So... do I have any choice?
 
 Regards,
 Ernesto

Not really. You either have to init your variables or turn off notices
in error_reporting() (or otherwise suppress them; i.e. display_errors =
off).



-- 
 Torben Wilson [EMAIL PROTECTED]
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-03-30 Thread Shane Wright

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


 Not really. You either have to init your variables or turn off notices
 in error_reporting() (or otherwise suppress them; i.e. display_errors =
 off).

initialising them with safe defaults is the thing to do - the point of the 
error is to warn about uninitialised variables (which, if register_globals is 
on, could be used by an attacker to make your scripts to bad things...)

- --
Shane
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8pmm85DXg6dCMBrQRAl0PAJ9W6iBFtaYtXBKnvmtfKPPVJzHWyACfRg91
6IXouixJwNAsLJDhvYyhnSs=
=DBej
-END PGP SIGNATURE-


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-03-30 Thread Lars Torben Wilson

On Sat, 2002-03-30 at 17:43, Shane Wright wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 
  Not really. You either have to init your variables or turn off notices
  in error_reporting() (or otherwise suppress them; i.e. display_errors =
  off).
 
 initialising them with safe defaults is the thing to do - the point of the 
 error is to warn about uninitialised variables (which, if register_globals is 
 on, could be used by an attacker to make your scripts to bad things...)
 
 - --
 Shane

Yes, this is my standard suggestion as well, but since Ernesto seemed
to be aware of the issues I decided not to press the point. 


-- 
 Torben Wilson [EMAIL PROTECTED]
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Undefined variables

2002-03-30 Thread Shane Wright

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


sorry, didnt get that that was your prefered method - didnt mean to step on 
your toes :)

S

On Sunday 31 March 2002 2:50 am, Lars Torben Wilson wrote:
 On Sat, 2002-03-30 at 17:43, Shane Wright wrote:
  -BEGIN PGP SIGNED MESSAGE-
  Hash: SHA1
 
   Not really. You either have to init your variables or turn off notices
   in error_reporting() (or otherwise suppress them; i.e. display_errors =
   off).
 
  initialising them with safe defaults is the thing to do - the point of
  the error is to warn about uninitialised variables (which, if
  register_globals is on, could be used by an attacker to make your scripts
  to bad things...)
 
  - --
  Shane

 Yes, this is my standard suggestion as well, but since Ernesto seemed
 to be aware of the issues I decided not to press the point.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8pm4K5DXg6dCMBrQRAsTLAJ9377x/gjRKbHrfcSYW11BKUgotgACfQmTw
x2rcCdMlPbAaPg8zAey7L/8=
=WVbB
-END PGP SIGNATURE-


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




RE: [PHP] Undefined Variables / PHP 4.0.4pl1

2001-05-18 Thread Johnson, Kirk

If you have access to php.ini, see the Error handling and logging section.
Else, see http://www.php.net/manual/en/ref.errorfunc.php

Kirk

 -Original Message-
 From: Martin Thoma [mailto:[EMAIL PROTECTED]]
 Sent: Friday, May 18, 2001 1:36 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] Undefined Variables / PHP 4.0.4pl1
 
 
 Hello !
 
 I just installed PHP 4.0.4pl1 over an existing PHP 4.0.1 on Win98 with
 Apache. Alle works greate, but I get a lot of warnings:
 
 Warning: Undefined variable: MyVariable in filename
 
 The warnings weren't there in the earlier version. How can I turn of
 these warnings ?
 
 Regards
 
 Martin
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: 
 [EMAIL PROTECTED]
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Undefined Variables / PHP 4.0.4pl1

2001-05-18 Thread Martin Thoma

Thanx a lot, I found it in php.ini !

Johnson, Kirk schrieb:

 If you have access to php.ini, see the Error handling and logging section.
 Else, see http://www.php.net/manual/en/ref.errorfunc.php

 Kirk

  -Original Message-
  From: Martin Thoma [mailto:[EMAIL PROTECTED]]
  Sent: Friday, May 18, 2001 1:36 PM
  To: [EMAIL PROTECTED]
  Subject: [PHP] Undefined Variables / PHP 4.0.4pl1
 
 
  Hello !
 
  I just installed PHP 4.0.4pl1 over an existing PHP 4.0.1 on Win98 with
  Apache. Alle works greate, but I get a lot of warnings:
 
  Warning: Undefined variable: MyVariable in filename
 
  The warnings weren't there in the earlier version. How can I turn of
  these warnings ?
 
  Regards
 
  Martin
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail:
  [EMAIL PROTECTED]
 

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]