48 points · by mdasen · 17y ago · 48 comments
PHP has many problems. We know this. There are millions of words online that will attest to this fact. The fact is, all these words are for naught if people don't step in and do something about it.
This site is mostly written by chx, one of the core developers of the PHP-based Drupal project. It's not meant to be a bashing of PHP or its authors.I've heard of damning with faint praise, but this is more like faint condemnation...
I could only find 2 posts in the website. Wake me up when it has at least a dozen articles.
0 == 'x'
results in bool(true)
Does anyone know the technical reasons for this?"As explained under 'read more', it's because 'test' will be cast to a number for comparison. Since 'test' isn't a number, it becomes 0, which is equivalent."
If you can keep it from devolving into thedailywtf.com then you'll have a very loyal reader in me. I work in PHP and I would love to hear a list of valid frustrations instead of the general PHP bashing.
"It's not meant to be a bashing of PHP or its authors."
And if so, does anyone understand how that site isn't mean to be a bashing of PHP? I mean, he's free to bash it if he wants, but does that even make sense?
echo "<?php if (0 == 'test') echo 'true???'; ?>" | php # => "true???"As it stands, PHP's equality operator is not an equivalence relation because it's not transitive. This is deeply unintuitive and logic-defying.
== is the type coerce/cast and then compare operator.
I agree with you about the way strings get converted to int instead of the other way around. I believe this is a backwards compatibility issue, and if they could change it they would, but it's too late.
It's also because of 1 == "01" would be false otherwise. And if you think "01" is strange you forget that all input to a php program comes from web forms, and is always a string.
Concepts and algorithms are universal. Operators and keywords are not.
Luckily, this is such a common need when learning a language that this information is kept all together in a tidy tabular way.
Because without it, I'd probably whip up an index.php and write something like print 'Welcome, ' + user.firstName;, get frustrated by parse errors, then by runtime errors, then write some impassioned comment about how deeply unintuitive it is to require prefixed variables and how using a dot for concatenation instead of a plus sign or ampersand is simply logic defying.
And that same table that explains concatenation and scope resolution is also going to give me a simple treatment on the == and === operators in this weakly typed language.
PHP is not an elegant language and given the choice, I'd nearly always prefer to be writing something else. But I took my time to respond to this because there's enough wrong with PHP that we don't need to resort to hyperbole to bash it.