3 ms·
As a rough generalization, all PHP code that involves "==" and "!=" should be considered broken. PHP introduced "===" and "!==" a long time ago, and every prog
by vog 12y ago
As a rough generalization, all PHP code that involves "==" and "!=" should be considered broken.
PHP introduced "===" and "!==" a long time ago, and every programmer should know that they have to use that, without any excuses.
Also, don't use "in_array($a, $b)", but use "in_array($a, $b, true)" instead.
- imakesnowflakes 12y ago>without any excuses... Oh yea? How about this, 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...
- vog 12y agoI don't see how "==" would help in that situation, other than "solving" this particular issue by opening another can of worms. You simply can't use php arrays for user-generated keys in a safe manner. At least you have to add some prefix like '_stuff_' to all keys, to avoid accidental conversions. And yes, this "proper" solution (Can you ever can say "proper" in php? Anyway ...) doesn't have to involve "==", but works perfectly (and preferably) with "===".
- josteink 12y agoSo what you're basically saying is that the "standard" variations and APIs which people will find and use are broken, and the ones actually working are hidden somewhere in the documentation. And you're saying you think this is just fine? In that case, I have a hammer to sell you, and I think you know which one. http://blog.codinghorror.com/the-php-singularity/ http://blog.codinghorror.com/the-php-singularity/
- vog 12y ago> And you're saying you think this is just fine? Not sure where you read this. I didn't provide any judgement of the situation. Strawman arguments like this should have no place on HN.