Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 07-15-2004, 11:35 AM   #1 (permalink)
Insane
 
trache's Avatar
 
[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*
__________________
"You looked at me as if I was eating runny eggs in slow motion." - Gord Downie of The Tragically Hip
trache is offline  
Old 07-15-2004, 11:38 AM   #2 (permalink)
Crazy
 
Location: Salt Town, UT
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)
Rawb is offline  
Old 07-15-2004, 07:24 PM   #3 (permalink)
Banned
 
cthulu23's Avatar
 
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.
cthulu23 is offline  
Old 07-16-2004, 07:03 AM   #4 (permalink)
Junkie
 
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:
if($fp = @fopen('some_file.dat','r')) {
 
fread($fp,filesize('some_file.dat'));
 
fclose($fp);

Prefixing the "@" symbol to a function name suppresses any error message that would be printed if the attempt to acquire a handle failed.
SinisterMotives is offline  
 

Tags
assignment, equality, php


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 04:24 PM.

Tilted Forum Project

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38