Re: [PHP] Boolean type forced on string assignment inside if statement
On Thursday 03 January 2013 10:26:39 Jim Giner wrote: > On 1/2/2013 2:02 PM, Marc Guay wrote: > > Something else that's happening with this, which makes it a Bad Idea > > (tm) is that when the operator is "or", as it is in my real life > > scenerio, the 2nd variable occasionally doesn't get populated if the > > first one returns true. > > > > if ($a = "foo" || $b = "bar"){ > > > > echo $a."".$b; > > > > } > > > > Returns > > foo > > > > And even worse, because I have this in a loop, what can happen is that > > if $b gets populated on one loop, it doesn't get reset for the next > > one so the data gets seriously bungled. > > > > Moral of the story: Don't be so fancy on your first day back after > > vacation. :) > > > > Marc > > You actually use statements like that in order to populate vars? > Whatever happened to "simple to understand, easy to maintain" coding > practices? > > The only time I use a single '=' symbol in an if statement is when I > forget to use two of them! Must be my old school, old languages habits > but this style of programming reminds me of the days when we used to > pack empty spaces in assembler code with constants or byte-size vars in > order to save memory back when memory was the most precious resource one > had. I have been watching this discussion with some amusement and I recall the days mentioned by Jim very well indeed! First, did the original poster realize that he was assigning a value to the variable $a in the 'if' statement? Assuming that he did, and this is not just a typo, then remember how the if statement evaluates an OR condition; that is, if the first variable is 'true' then the true path is followed because there is no reason to go further. So the result is EXACTLY what one would expect. $a is true (ie it is not set to a 'false' value, whatever PHP uses for false) and $b is "bar" because that is what it is set to. Since the evaluation is within a bracket, the interior values ($a, $b) are set BEFORE the if condition is evaluated. I see neither a bug in PHP nor a variance from the expected result here. Regards, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Boolean type forced on string assignment inside if statement
On Thursday 03 January 2013 11:33:22 Marc Guay wrote: > > First, did the original poster realize that he was assigning a value > > to the variable $a in the 'if' statement? > > Hello, > > Yes, I did, and if you read my responses you can see that I came to > the realisations you describe. I don't think that anyone suggested > there was a bug. > > > $a is true (ie it is not set to a 'false' value, > > whatever PHP uses for false) and $b is "bar" because that is what it > > is set to. Since the evaluation is within a bracket, the interior > > values ($a, $b) are set BEFORE the if condition is evaluated. > > Regarding this I'm a bit confused. In the case of an OR operator, $b > is not "bar" because it follows the "true" path as you said earlier. > Probably just a glitch in the English language. I'll file a bug for > that. > > Marc Hi Marc: I'm not at all sure of that. There are two things happening in parallel here: first the interior of the brackets is evaluated as necessary, in this case the $a is set to "foo" and the $b is set to "bar". Then the exterior part of the statement is evaluated: if ($a. ). It is this last operation that results in the path selection through the code, and in this case $a is "true", $b is not evaluated. mind you I'm basing this on my university basic programming course from almost 50 years ago :-) Regards, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Expansion of Apache definitions
I recently made a posting on the Apache users group regarding recovering the client IP address using the $_SESSION['REMOTE_ADDR'] function in PHP. I received the following caveat from another developer: -start quote You may want to update that. Since 2.4, apache makes the distinction between the the two different REMOTE_ADDR candidates: the peer making the TCP connection, and the client making the HTTP request. In other words, the nearest proxy and the end-user. The latter is of course very easy to spoof, but is nevertheless the one most applications want. --end quote Is there any development underway in PHP to have both of these addresses available in the $_SESSION global variable? Regards, John -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] PHP fails to install on Ubuntu 12.10. What's going on?
On Thursday 14 February 2013 14:20:06 Chris Bergstresser wrote: > Hi all -- > >I've got a cloud server on Rackspace. If I bring up a fresh Ubuntu > 12.10 machine image, and type "apt-get install php5" it seems to > install fine. But if I then type "php -version" I get "PHP Parse > error: syntax error, unexpected end of file in Command line code on > line 1". > >What went wrong? How can I fix it? > > -- Chris type php --version There are two - preceding the word version. J. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php