This topic is locked

PHP operator syntax

9/2/2008 3:52:00 AM
PHPRunner Tips and Tricks
T
thesofa author

This is a useful page to consult to check to see if you are using the PHP operators correctly, I have been caught out a few times with using == instead of = in an expression.

M
michaelmac 10/22/2008

Here is a trick I learned when I was programming in C/C++ ... I just reverse order of my compare in an if(). I mean it works in PHP, not in java.
e.g.
$a = 100;
if($a==100)

// then do something
this works fine, but if you entered if($a=100), nothing would complain because it becomes an assignment
BUT
what would happen if you did this,
if(100==$a)

// still works... no problem
but if you did this if(100=$a)

// fails because of the left-hand rule of assignments
I hope that suggest helps
Thanks
Mike

T
thesofa author 10/22/2008

nice one, thanks, i shall use that

does it work in the NULL case?

ie

if($qq===NULL)

is is OK to put

if(NULL===$qq)
???