![]() |
[php] equality or assignment?
I have seen the following code:
if ($blah = do_this()) { [...] }; While I'm quite a competent programmer, I still have an icky feeling when it comes to PHP only because the documentation on the website blows. and no one except the PHP programmers know what they're doing. So what is this statement performing? Is it assigning do_this() to $blah and returning true (all the time) or testing if $blah equals do_this() (which I don't think because usually == is equality and = is assignment)? *shrugs* |
It is setting $blah to the output of do_this(), and the if statement is also getting the output of do_this() to evaluate to be true or false (basically, if do_this() returns false, the if statement won't fire)
|
PHP is very C like in it's syntax, so = is the assignment operator and == is an equivalence test. === tests for type equivalence as well as value equivalence.
|
That construct is most frequently used to test whether a resource handle can be acquired so that your script can determine whether it can perform operations on the handle. For example, the following code would test to see if $fp is a valid file handle:
PHP Code:
|
All times are GMT -8. The time now is 08:55 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project