473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Best method of doing simple flags

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
Jul 17 '05 #1
2 1473
*** harryman100 escribió/wrote (18 Sep 2004 06:05:55 -0700):
$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?


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
--
Jul 17 '05 #2
On 18 Sep 2004 06:05:55 -0700, harryman100 wrote:
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?


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

That way there is no integer to boolean conversion.

Berislav
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
7
by: loquak | last post by:
Greets. I wonder which way would be the best for holding some state flags in terms of memory use and efficiency. a) struct FLAGS { bool flag1 : 1; bool flag2 : 1;
30
by: Philippe Bertrand | last post by:
Is this a bug in the C# compiler or CLR runtime? enum MyEnum { ZERO = 0, ONE = 1, TWO = 2 } class Foo { public Foo(string,object) { ... } public Foo(string,MyEnum) { ... } } Foo f = new...
12
by: Aaron Smith | last post by:
What is the best way to handle data in a multiple user environment? We have forms that will allow users to add edit and delete data from a table on SQL server. The data could be edited on multiple...
3
by: cartoper | last post by:
I am currently doing some R&D. The objective is to learn how to invoke methods via reflection using the InvokeMember method. The InvokeMember method throws an exception: Method...
2
by: Tom | last post by:
Just wondering what others were doing to clear the errorprovider? What I mean is that, during processing of a windows form, I may turn on (i.e. SetError) the errorprovider for various fields. Now,...
13
by: Alan Silver | last post by:
Hello, MSDN (amongst other places) is full of helpful advice on ways to do data access, but they all seem geared to wards enterprise applications. Maybe I'm in a minority, but I don't have those...
1
by: MrNobody | last post by:
I'm going to be creating shapes in a OnPaint method of an extended Panel object, and I need mouse event functionality (onClick, onMouseOver) that kind of stuff... what's the best way to go about...
7
by: Steve | last post by:
I am building an object library for tables in a database. What is the best practice for creating objects like this? For example, say I have the following tables in my database: User: - Id -...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.