if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????' ; 6 1395
mrbog wrote: if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????' ;
I posted something about this the other day.
When comparing a string with a number the string is first evaluated as a
number, which in the case of the above is example is 0. So in effect
you are comparing 0 with 0.
A much safer test is
if(0 === "asdfasdf")
which will evaluate the condition as false. Note I'm using === here and
not ==
=== compares the types strictly whereas == does not.
And yes, I agree it's stupid. Very easy to catch people out.
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Hi,
Chris Hope wrote: mrbog wrote: if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????' ; I posted something about this the other day.
When comparing a string with a number the string is first evaluated as a number, which in the case of the above is example is 0. So in effect you are comparing 0 with 0.
Sorry, this is not correct. The string and the number will be casted to
a boolean value. And a non empty string is definitly true. 0 will be
casted to false.
$ php -r 'if (0 == "asdf") echo "true\n"; else echo "false\n";'
true
if(0 === "asdfasdf")
which will evaluate the condition as false. Note I'm using === here and not ==
=== compares the types strictly whereas == does not.
This is correct.
$ php -r 'if (0 === "asdf") echo "true\n"; else echo "false\n";'
false
Regards
Paul.
On 11/06/2005 11:35, Paul Wellner Bou wrote: Chris Hope wrote:
[snip] When comparing a string with a number the string is first evaluated as a number, which in the case of the above is example is 0. So in effect you are comparing 0 with 0.
Sorry, this is not correct.
Unless the documentation is wrong, it certainly is correct.
From Comparison Operators:
"If you compare an integer with a string, the string is converted to
a number."
and from Strings:
"If the string starts with valid numeric data, this will be the value
used. Otherwise, the value will be 0 (zero)."
[snip]
Mike
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Paul Wellner Bou wrote: Chris Hope wrote: mrbog wrote: if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????' ;
I posted something about this the other day.
When comparing a string with a number the string is first evaluated as a number, which in the case of the above is example is 0. So in effect you are comparing 0 with 0.
Sorry, this is not correct. The string and the number will be casted to a boolean value. And a non empty string is definitly true. 0 will be casted to false.
It is correct. It's in the manual. Check the first example in the code
block at the following manual page: http://www.php.net/manual/en/languag...comparison.php
If you were right, then the above code snippet would not output the
text. Try running the code; it *does* output the text.
[rest of comments snipped]
--
Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
Paul Wellner Bou said the following on 11/06/2005 11:35: Hi,
Chris Hope wrote:
mrbog wrote:
if (0 == 'asdfasdf' ) echo 'WHAT THE FUCK??????????' ;
I posted something about this the other day.
When comparing a string with a number the string is first evaluated as a number, which in the case of the above is example is 0. So in effect you are comparing 0 with 0.
Sorry, this is not correct. The string and the number will be casted to a boolean value.
Wha?? Since when does that ever happen? If you did something like:
if (4 == 7) ...
4 and 7 are most definitely *not* converted to Booleans. The same
applies for the example above.
--
Oli
Chris Hope wrote: Paul Wellner Bou wrote:Chris Hope wrote:When comparing a string with a number the string is first evaluated as a number, which in the case of the above is example is 0. So in effect you are comparing 0 with 0.
Sorry, this is not correct. The string and the number will be casted to a boolean value. And a non empty string is definitly true. 0 will be casted to false.
It is correct. It's in the manual. Check the first example in the code block at the following manual page: http://www.php.net/manual/en/languag...comparison.php
If you were right, then the above code snippet would not output the text. Try running the code; it *does* output the text.
Sorry... I was confused. Shame on me.
The code sample I gave contradicts my words.
Ignore my post... ;)
Regards
Paul. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Peter |
last post by:
Company thought DB2 will be better than Oracle.
The bottom line is when you do select, the system crash.
I think it may take 4-5 years for DB2 to reach Oracle standard.
Peter
|
by: Generic Usenet Account |
last post by:
I am going through some legacy code that has an "isNull()" method
defined on certain classes. I can see that this can be a good way to
eliminate certain types of crashes, by making this the first call in a
method (and bailing out immediately if it is true). However, if this
is such a good idea, why is it not common industry practice?
Mohan
|
by: Mike MacSween |
last post by:
S**t for brains strikes again!
Why did I do that? When I met the clients and at some point they vaguely
asked whether eventually would it be possible to have some people who could
read the data and some who couldn't but that it wasn't important right now.
And I said, 'sure, we can do that later'.
So now I've developed an app without any thought to security and am trying
to apply it afterwards. Doh!, doh! and triple doh!
|
by: dreamcatcher |
last post by:
I always have this idea that typedef a data type especially a structure
is very convenient in coding, but my teacher insisted that I should use
the full struct declaration and no further explanations, so I wonder is
there any good using typedef ? and I also know that when a data type
being typedefed become an abstract data type, so what exactly is an
abstract data type, is it any good ?
--
Posted via http://dbforums.com
|
by: Sensei |
last post by:
Hi!
I'm thinking about a good programming style, pros and cons of some
topics. Of course, this has nothing to do with indentation... Students
are now java-dependent (too bad) and I need some serious motivations
for many issues... I hope you can help me :) I begin with the two major
for now, others will come for sure!
- function variables: they're used to java, so no pointers. Personally
I'd use always pointers, but why could be better...
| |
by: tony |
last post by:
If you have any PHP scripts which will not work in the current releases
due to breaks in backwards compatibility then take a look at
http://www.tonymarston.net/php-mysql/bc-is-everything.html and see if
you agree with my opinion or not.
Tony Marston
http://www.tonymarston.net
|
by: sam.s.kong |
last post by:
Hi!
I've been programming ASP for 5 years and am now learning PHP.
In ASP, you can use GetRows function which returns 2 by 2 array of
Recordset.
Actually, it's a recommended way in ASP when you access DB as it
disconnects the DB earlier.
Also, it's handy as you can directly access any data in the array
without looping.
|
by: Michael |
last post by:
Hi,
I'm having difficulty finding any previous discussion on this -- I
keep finding people either having problems calling os.exec(lepev), or
with using python's exec statement. Neither of which I mean here.
Just for a moment, let's just take one definition for one of the
|
by: JT |
last post by:
Here is the overall structure I will be referring to:
End-program
ProvideWorkFlow.dll
Forms and methods that properly manipulate calls to methods in
AccessUtils
AccessUtils (a web service)
Hide.dll
methods and data I want to remain hidden
I have a DLL, Hide.dll, that contains methods that I want to handle for
|
by: mike3 |
last post by:
Hi.
Is this a good idea?:
<begin code>
/* Addition operator: += */
const BigFix &BigFix::operator+=(const BigFix &rhs)
{
ErrorType err;
int lhs_sign = sign, rhs_sign = rhs.sign;
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |