3 ms·
No. http://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_this_php_bashing/cpjhx04 http://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_this... Read that
by imakesnowflakes 12y ago
No.
http://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_this_php_bashing/cpjhx04 http://www.reddit.com/r/PHP/comments/2zhg6z/how_true_is_this...
Read that and tell me that it is Ok..And see how that comment has been downvoted. That is PHP community for you. In 2015.
- ceejayoz 12y agoA single downvote on a subreddit is indicative of the PHP community as a whole? Well, shit, time to ditch the language... Why would you think the third value in ['ab', 'cd', '10', 'gh', '24'] would have a key of '10'? That's the value, not the key. The docs are quite clear on how this works: http://php.net/manual/en/control-structures.foreach.php http://php.net/manual/en/control-structures.foreach.php foreach (array_expression as $value) vs. foreach (array_expression as $key => $value)
- imakesnowflakes 12y ago>Why would you think the third value in ['ab', 'cd', '10', 'gh', '24'] would have a key of '10'? That's the value, not the key. Can you please take one more look? Values in the first array is used as keys to set values in the second array..
- juliangregorian 12y agoYou've misunderstood. He only uses that (flat) array to populate the key-value array $c. His problem is that PHP oh-so-helpfully converts the string value to an int value. It's actually impossible to have string values as indices of an array when they are parsable as numbers in PHP. One of the many foibles that stem from conflating flat arrays and key-value maps. (For a real fun time, try reading the docs for array_merge.) Anyway, it's not surprising. /r/PHP doesn't handle criticism well.
- joesmo 12y agoIt is ok. That's how the language is designed so that arrays cover both hash-map use cases and traditional numerically indexed array use cases. The behavior is well documented and in this specific example, using a == instead of a === would cause the desired result. The poster of that comment should RTFM.
- imakesnowflakes 12y ago>The poster of that comment should RTFM... I am not sure I should go read the manual before setting a string key in an array to make sure that the specific string does not falls under some kind of special treatment. When normal people see that they can set string keys on something, they would assume that it work for all strings regardless of their content. And regarding PHP manual, it does not even have fundamental stuff right. This comment is from an ex php core developer. http://www.reddit.com/r/lolphp/comments/2md8c0/new_safe_casting_function_rfc_casting_10_to/cm3dpdj http://www.reddit.com/r/lolphp/comments/2md8c0/new_safe_cast... >using a == instead of a === would cause the desired result Except using == will result in a hundred other weird behaviors that have caused numerous many bugs and security vulnerabilities, that every one uses === with out exception..