LF-DevJourney
LF-DevJourney

Reputation: 28549

Inner difference of if('0') between C and PHP?

Will someone explain the inner difference of if('0') between C and PHP? In C, if('0') gets false, while in PHP gets true.

Upvotes: 1

Views: 73

Answers (1)

Mike Robinson
Mike Robinson

Reputation: 8955

Well, the "C" language, which dates from the 1970's, is a good bit more literal than PHP! :-)

First of all, the "C" language really has no concept at all of "a string data type." "None of that had been invented yet."

Furthermore, the compiler "presumed that you actually knew what you were doing." (That is to say, "that you would not feed it 'nonsense.'") Being a very literal language, it presumed that you must be thinking the same way.

Fast-forward at least one human generation, and we come to "PHP." CPU's are now vastly more-powerful than a PDP-7 ever was, and memory is an order-of-magnitude bigger, and by now we're trying to "bend the language's interpretation of things, to better match "ordinary human" meanings, instead of the other way around.

Thus, the PHP language sees "0" as "false-y." Instead of restricting its point-of-view to "a particular storage representation," as C is designed(!) to do, PHP sees "0" as being "zero" ... even though, strictly-speaking, it is "a string" ... and thus sees it as: "false-y."

Yeah ... "potential interpretations of the meaning of source-code" have indeed "changed in forty-plus(!) years ..."

Upvotes: 3

Related Questions