Connecting Tech Pros Worldwide Help | Site Map

Best method of doing simple flags

  #1  
Old July 17th, 2005, 09:40 AM
harryman100
Guest
 
Posts: n/a
Hi,

Currently when I want to set a flag to detect later on in the script,
I do this:

$something_flag = 1;

then later on in the script:

if ($something_flag) {
do_something();
}

Is this the best way of doing simple yes/no tests in PHP, or is there
another way I haven't discovered yet?

Thanks,
Harry
  #2  
Old July 17th, 2005, 09:40 AM
Alvaro G. Vicario
Guest
 
Posts: n/a

re: Best method of doing simple flags


*** harryman100 escribió/wrote (18 Sep 2004 06:05:55 -0700):[color=blue]
> $something_flag = 1;
>
> then later on in the script:
>
> if ($something_flag) {
> do_something();
> }
>
> Is this the best way of doing simple yes/no tests in PHP, or is there
> another way I haven't discovered yet?[/color]

Using TRUE or FALSE instead of 1 and 0 is almost the same, but slightly
clearer. Other than that, I see nothing wrong in your method.


--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
  #3  
Old July 17th, 2005, 09:40 AM
Berislav Lopac
Guest
 
Posts: n/a

re: Best method of doing simple flags


On 18 Sep 2004 06:05:55 -0700, harryman100 wrote:
[color=blue]
> Hi,
>
> Currently when I want to set a flag to detect later on in the script,
> I do this:
>
> $something_flag = 1;
>
> then later on in the script:
>
> if ($something_flag) {
> do_something();
> }
>
> Is this the best way of doing simple yes/no tests in PHP, or is there
> another way I haven't discovered yet?[/color]

Only slightly better is to use actual boolean values, i.e. $something_flag
= true;

That way there is no integer to boolean conversion.

Berislav
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
"error_reporting" setting not being recognized in my php.ini file laredotornado@zipmail.com answers 1 October 3rd, 2006 03:25 PM
Why doesn't strrstr() exist? Christopher Benson-Manica answers 149 November 15th, 2005 03:33 AM
Cannot use mail() in IE, only works in a debugger--help baustin75@gmail.com answers 8 October 5th, 2005 06:15 PM
Trouble with system() function Penn Markham answers 9 July 17th, 2005 05:43 AM