

PHP WTF: A PHP Annoyance Posted Every Day - mdasen
http://www.phpwtf.org/

======
apgwoz
Maybe I shouldn't, but I find it sort of maddening that, PHP WTF would be
powered by software written in PHP. I mean, if it bothers this guy to the
extreme that he would go register a domain, and put up a website about it, it
shouldn't be much trouble to learn a brand spanking new programming language
that doesn't have all the problems he's discussing, right?

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.

~~~
idlewords
People who make heavy use of a language are in a good position to vent about
its shortcomings. Sometimes a language is the best tool for the job despite
its many deficiencies, and I'd much rather read these kind of rants by someone
who knows the language inside out. I hate PHP more than I hate my own mother,
and yet I still chose it for my most recent project. Every programming
language has shortcomings, it's just a question of picking the best
shortcomings for the job.

~~~
apgwoz
> Every programming language has shortcomings.

Name a language with more. I'll wait.

~~~
j_baker
INTERCAL

------
niyazpk
"Posted Every Day" ?

I could only find 2 posts in the website. Wake me up when it has at least a
dozen articles.

~~~
Pistos2
Agreed; it might have been better marketing to have at least 6 posts up before
announcing the site.

------
bemmu
If you want the strict non-coerced equality, I think you are supposed to use
=== as in javascript.

------
Deestan
So:

    
    
      0 == 'x'
    

results in

    
    
      bool(true)
    

Does anyone know the technical reasons for this?

~~~
rbanffy
daeken explained it quite well. From his post:

"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."

------
AlphaEvolve
if ($countarticles == '2') { postponeLaunch($credibility); }

~~~
Jem
No need for the '' around 2 ;)

~~~
LogicHoleFlaw
It's PHP, it works anyway.

~~~
apgwoz
Maybe he'll pay you for writing his 3rd post.

------
xtho
If they ever make it to posting #3, there is a chance this site will outlive
php.

------
erikwiffin
You need a submission form. or not... there's no way you could sort through
all the submissions you'd get.

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.

------
TallGuyShort
Did anyone read this disclaimer at the bottom of the page?

"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?

~~~
RossM
Yes. While it seems to be the trend to bash on PHP there's nothing wrong with
discussing it's shortcomings in a constructive manner.

------
AlphaEvolve
please someone create aspwtf

~~~
j_baker
While we're doing outdated technologies, can we also do a COBOL wtf?

------
DougBTX
OK, I'm stumped, why is this?

    
    
      echo "<?php if (0 == 'test') echo 'true???'; ?>" | php # => "true???"

~~~
daeken
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.

~~~
Sharlin
Which is, of course, a deeply broken way to handle the situation. If multi-
type comparisons have to be supported at all, at least one ought to cast the
narrower type to the wider one! In this case, the int argument ought to be
cast to string, because all ints can be uniquely represented as a string, but
not the other way around.

As it stands, PHP's equality operator is not an equivalence relation because
it's not transitive. This is deeply unintuitive and logic-defying.

~~~
ars
== is not the equality operator. === is the equality operator.

== 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.

~~~
catch23
in javascript:

1 == '01' --> true

0 == 'x' --> false

1 == '1' --> true

true == 'asdf' --> false

'-2' == 2 --> true

'-2' == 0 --> false

Seems like in javascript, the coercing is much more sane. In php, all of the
above statements would end up true.

~~~
BerislavLopac
The funny thing is that in Javascript:

12 == parseInt('012')

returns false. :)

~~~
mhansen
A leading zero usually means 'this number is octal', so parseInt returns 10.
Not very intuitive notation, however.

------
petercooper
Unlike many blogs, at least this one will easily have enough material to keep
going for several years.. ;-)

------
lsb
That's like shooting fish in a barrel.

~~~
quizbiz
But how do you get the fish into a barrel?

~~~
dugmartin
You shoot them in the lake.

