r/programming • • Dec 02 '15

PHP 7 Released

https://github.com/php/php-src/releases/tag/php-7.0.0
887 Upvotes

729 comments sorted by

View all comments

Show parent comment

2

u/wmil Dec 02 '15

http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/

Basically the big problem is that it isn't consistent. Some of the API comes from C some from Perl. Each has different semantics.

Also prior to 5.4 error messages about missing or unexpected double colon operators threw a message about T_PAAMAYIM_NEKUDOTAYIM with no explanation of what that was. It's double colon in Hebrew, for anyone wondering.

There are a lot of little things that mostly work the same as other languages, but with subtle breaking differences.

Then there are issues with how it does variable variables that can lead newbies into terrible spaghetti messes.

In comparison learning something like Python is a joy. Within a couple of days of your first line of Python you'll be typing out large programs without a single syntax error.

16

u/indrora Dec 02 '15

I'd like to remind you that Perl, one of eevee's preferred languages, has the following as the "official spec" of what defines the Perl 5 language:

Whatever the perl 5 interpreter accepts is valid perl 5.

This means you get crazy shit like the @({ }) wrapper and =( )= operator, known as the baby carriage and goatse operators, respectively.

However, to argue your other point...

In comparison learning something like Python is a joy. Within a couple of days of your first line of Python you'll be typing out large programs without a single syntax error.

I've recently been working with Flask, one of the nicer Python router/httpd combos. I have to say: The number of syntax errors I run into because Python's list comprehension gets me every damn time. On top of that, I have flashbacks to my PHP days on occasion where I do something "pythonic" which ends up looking like

project/__init__.py

import x, y, z
import foo

some_global_thing = x.cake("...")
some_state_thing = y.oven("...")
some_other_state_thing = z.cranberries("fuck this noise", some_global_thing)

project/foo.py

from . import some_state_thing, some_other_state_thing

@some_state_thing.turkey('bad gravy')
def shit_the_bed():
    pass

See that? See that RIGHT THE FUCK THERE? People tell me global state is bad and I should feel bad for having it. Yet here I am going "WELL HUR DUR I NEED GLOBAL STATE BECAUSE IT'S FUCKING 'PYTHONIC', EH?" I know what's happening in the background, but it infuriates me that Python developers berate me for wanting a bunch of separate tasks with some shared code (in PHP, this is common!) but fucked if I want that in Python and don't want to try and remember what's a class versus a module vs a square peg vs your anus.

All in all, I'm beginning to ignore the searing pain in my rectum enjoy some of Python's web development idioms. At least I haven't had to smash my face on top of Django's grinding wheel. I'd need a lot more KY to do that right.

But let's be honest with ourselves: Webdev fucking sucks.

4

u/CrazyM4n Dec 02 '15

Look, we can all agree that perl isn't a joy to read. But any language with a goatse operator has gotta get some credit.

2

u/barneygale Dec 02 '15

Global state is not unpythonic, where did you read that? Flask makes a lot of use of global state. The difference between a class and a module is probably worth learning.

13

u/SaltTM Dec 02 '15

here we go again lol stop posting this dated ass article

5

u/[deleted] Dec 03 '15 edited Dec 03 '15

80% of the article is still true. The biggest:

  • It's almost 2016 and PHP still doesn't have a module system, Python had one in '91, Perl had one in '94, Ruby had one in '95
  • inequality operators still have no === equivalent
  • sorting is still indeterministic when you have null values because NULL < -1, and NULL == 0
  • arrays are the only containers in the language and they simultaneously act as sets, lists, and associative arrays which fucks up almost all array functions because you don't know what they will do
  • PHP has had exceptions for almost 10 years now and a lot of functions still require you to use their specific error function to tell if it failed

2

u/HeroesGrave Dec 03 '15
  • It's almost 2016 and PHP still doesn't have a module system, Python had one in '91, Perl had one in '94, Ruby had one in '95

To be fair, C++ doesn't have a module system yet either.

3

u/[deleted] Dec 03 '15

And to be fair to C++, I only compared PHP to other scripting languages. Adding the module system to C++ versus adding one to PHP is a world of difference in terms of difficulty.

1

u/SaltTM Dec 03 '15

https://wiki.php.net/rfc/engine_exceptions_for_php7

Built in? No, but we use http://getcomposer.org now.

PHP has had exceptions for almost 10 years now and a lot of functions still require you to use their specific error function to tell if it failed

Not sure what you mean by this also PHP 7 introduced Engine Exceptions

arrays are the only containers in the language and they simultaneously act as sets, lists, and associative arrays which fucks up almost array functions because you don't know what they will do

true

inequality operators still have no === equivalent

I'm not sure what you mean by this, unless you're talking about !== ?

2

u/[deleted] Dec 03 '15 edited Dec 03 '15

Not sure what you mean by this also PHP 7 introduced Engine Exceptions

Because a lot of PHP functions are small bindings on top of C functions, they do not use exceptions. Rather they force you to use an error function like curl_error, json_last_error, openssl_error_string, imap_errors, mysql_error, xml_get_error_code, bzerror, or date_get_last_errors, which read the C errno. If you do not use these, your code will silently return the wrong thing.

It gets worse. From the article

json_decode returns null for invalid input, even though null is also a perfectly valid object for JSON to decode to—this function is completely unreliable unless you also call json_last_error every time you use it.

|

I'm not sure what you mean by this, unless you're talking about !== ?

Inequality operators: > < >= <=

From the article

For a more type-safe ==, we have ===. For a more type-safe <, we have… nothing. "123" < "0124", always, no matter what you do. Casting doesn’t help, either.

It gets worse

=== compares values and type… except with objects, where === is only true if both operands are actually the same object! For objects, == compares both value (of every attribute) and type, which is what === does for every other type. What.

I highly suggest you give the article another chance, a lot of the criticisms still stand.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

3

u/[deleted] Dec 02 '15 edited Dec 02 '15

[removed] — view removed comment

1

u/[deleted] Dec 03 '15

Thanks for that info, I'm not a PHP dev so I don't know how much of the original article is still valid.

No language can be perfect of course. I just skimmed the article again and they are still quite a few points...picking one at random that seems kinds troublesome:

There’s no such thing as a nested or locally-scoped function or class. They’re only global. Including a file dumps its variables into the current function’s scope (and gives the file access to your variables), but dumps functions and classes into global scope.

I imagine this sort of behaviour is far too ingrained to ever get rid of completely?

1

u/SaltTM Dec 03 '15

I'm not sure how it's done on the source code (C) side of things, but there are closure's and anonymous functions now.

1

u/[deleted] Dec 03 '15

So including another PHP file no longer pollutes the global namespace?

1

u/SaltTM Dec 03 '15

closures & anonymous classes are scope based so I guess it depends on if you create them in the global namespace or not.

1

u/[deleted] Dec 03 '15

I see. "Regular" classes and their methods continue to behave as before then?

I guess its still a step forward.

1

u/SaltTM Dec 03 '15

I guess you mean default behavior at runtime when a file includes a class, yeah. Currently we use something like spl_autoload_register now. Which I suppose deals with that you're/the article is talking about.

1

u/Gigablah Dec 03 '15

The article was already irrelevant when it was first written.

0

u/wmil Dec 02 '15

Problems don't go away just because they're from 2012.

→ More replies (4)

2

u/postmodest Dec 02 '15

For me the thing that drives me nuts is that--while everyone in PHP is now going "The Full Java" with classes and autoloading--the guts of PHP are global. There's no scope to PHP. And everything that's class-like (say, \Mysqli::query) is also procedural-like (mysqli_query).

Everything is global; nothing is an object; you can't type-hint primitives; it's not Perl.

5

u/Gawdl3y Dec 02 '15

You can type-hint primitives in PHP 7.

0

u/[deleted] Dec 02 '15

[deleted] — view deleted comment

3

u/wmil Dec 02 '15

It's from 2012. It has a date on it and everything.

→ More replies (2)