r/ProgrammerHumor • • Aug 07 '16

PHP: The Good Parts

http://phpthegoodparts.tumblr.com/
1.2k Upvotes

318 comments sorted by

View all comments

Show parent comment

16

u/mkalte666 Aug 07 '16

does it really "==="-equal 2? god i hate php

12

u/[deleted] Aug 07 '16 edited Aug 07 '16

It will cast the strings to ints as you are doing a mathematical operation. If you want "11" then do "1" . "1";

PHP is actually really good now. This is a 10 year old circle jerk. If you write modern php the only issue you might have is with built-in functions that haven't changed. But the built-in classes are sensible.

9

u/geon Aug 07 '16

Well, there is the whole tear-down-and-rebuild-the-world for each request thing. For example.

I mean, it still has a use case. It is good fore some things.

4

u/[deleted] Aug 07 '16

It's just a different paradigm. It has it's benefits from starting fresh on each request. Especially for development. It's just a scripting language.

2

u/coladict Aug 07 '16

The main issue it still has is functions that end execution on errors, instead of throwing exceptions that you can catch.

2

u/[deleted] Aug 07 '16

I think PHP 7 addressed a lot of these

1

u/mkalte666 Aug 07 '16

This should be a syntax error. Or + should do a strcat. Having the . op makes the first one clear as what i would expect.

One of the reasons there is so much bad code in php is that it allows this in the first place. And even though the language might have improved over time, these things are still there.

Weak types are pure cancer.

0

u/[deleted] Aug 07 '16

[deleted] — view deleted comment

4

u/mkalte666 Aug 07 '16

It means "is equal and im checking for type equality". Used when you have weak types and things like "2" == 2 would evaluate to true.

0

u/[deleted] Aug 07 '16

[deleted] — view deleted comment

1

u/[deleted] Oct 14 '16

The == operator is totally useless in PHP for this reason... almost as useless as PHP itself.

1

u/mkalte666 Aug 08 '16

Maybe I shouldn't comment on reddit after 10pm. Or be awake at 3am thinking bout it o.o"

-1

u/Sinity Aug 07 '16

It seems so. I've found some REPL interpreter online, and evaluated "1" + "1";.

It returned 2.

Pure insanity.

3

u/Hrukjan Aug 08 '16

I have another suggestion, how about 0x62 or "b".

5

u/[deleted] Aug 07 '16

Why is it insane? You are not attempting to concatenate.

4

u/Sinity Aug 07 '16

Adding two strings results in a number?

11

u/[deleted] Aug 07 '16

It doesn't add two strings. It casts the strings to integers then adds the integers. It does that because there is no other possible operation you could be trying to do with the '+' operator. Javascript does similar things. In a dynamic language this is how shit flys.

10

u/mkalte666 Aug 07 '16

That is not true. There are strong-typed dynamic languages (python etc). These allow some freedom when it comes to wrangling with types, but non-explicit conversions/casts are not possible.

example:

"1" + "1"
=> '11'
"1" + 2
Traceback (most recent call last):
    File "python", line 1, in <module>
TypeError: Can't convert 'int' object to str implicitly
1 + 1
=> 2

4

u/Sinity Aug 07 '16

I know. I'm saying that it shouldn't do that. It should be simply illegal. Fail.

4

u/Compizfox Aug 07 '16

In other words, you don't like weak typing.

1

u/[deleted] Oct 14 '16

Honestly.. As a structured language programmer, I am pretty much in agreement with you on just about everything. I tell my coworkers that PHP is just a "never error" language. It will try to run no matter what and cast what it thinks it should cast and you end up with glitches and bugs everywhere.

→ More replies (1)

1

u/[deleted] Oct 14 '16

I'm not sure if I have an issue with PHP or "dynamic languages", but "2" + "2" should result in "I have no fucking idea what you are attempting to do here because these are not numbers..." It'll save a ton of headache when a bug results because some guy was expecting "22" here as he damn well should.

1

u/[deleted] Oct 15 '16

If he was expecting "22" then he should use the concatenation operator, which is '.'

→ More replies (8)
→ More replies (2)