Live data from Hacker News

PHP 8: Before and After

stitcher.io

291–300 of 346 posts

Re: PHP 8: Before and After

#291

Earlier quoted context omitted.

> Python is not suitable for complex multi-layered systems But PHP is? I cannot imagine a "complex multi-layered system" for which PHP is a better solution than a Python stack.

PHP has (almost) complete strong typing system and all the bells and whistles of OOP needed to implement said systems using proper patterns and methodologies and make it modular and testable enough to be robust and supportable for a long time.

Python has literally all of those things, and has been strongly (but dynamically) type from the very beginning. PHP is still weakly typed today. This code doesn't raise a warning or anything:

  $ php --version
  PHP 7.3.11 (cli) (built: Jun  5 2020 23:50:40) ( NTS )
  Copyright (c) 1997-2018 The PHP Group
  Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
  
  $ php -r 'echo "123" + 45;'                                                                
  168
Contrast with Python:

  Python 3.8.3 (default, Jun  1 2020, 10:55:34)
  >>> "123" + 45
  Traceback (most recent call last):
    File "", line 1, in 
  TypeError: can only concatenate str (not "int") to str

Re: PHP 8: Before and After

#292

PHP is a perfect language for webdev and automation: much faster and lightweight than python, good package ecosystem. I do all my process automation tasks in PHP and it's been such a pleasure.

I too use php for automation. It has a lot of "built ins" that are always there (reading csv files for example/ json reading), which I find makes things a little easier for a lot of simple things.

if i have to crunch numbers in a script I like R, or Python w/ Pandas

Re: PHP 8: Before and After

#293

Earlier quoted context omitted.

I haven't found any good arguments against PHP in the comments here, just pure hate. Let's name a few of the arguments people are making: 1. Its variables start with $ and that is ugly: I mean, come on, I won't even entertain this bigotry. 2. It used to be better before: This is just pure nonesense, before OOP PHP wasn't good to create any big and well-structured application, it is ironic because most of the bad opin…

You're not being fair to the argument #3. PHP is becoming a less good Java. That's the problem. It's like Java, except it doesn't have generics, doesn't have real data structures (List, HashMap, Deque), no threads or async, no method/function reference or typed function parameters, etc. So the whole "It's trying to be Java" is more like "What does it offer that's better than Java? Because Java has stuff that is bette…

> it doesn't have generics

It doesn't need them IMO. It brings no benefit to the language, really. They would need to be type checked at runtime, which can become quite expensive. Static analysis is a better option for an interpreted language. Read this answer from Nikita (one of the top PHP contributors) https://www.reddit.com/r/PHP/comments/j65968/ama_with_the_ph...

> doesn't have real data structures

Untrue. See https://www.php.net/manual/en/book.spl.php It's usefulness is limited though, because it's rare that you need those types of data structures for web applications.

> no threads or async

Untrue. All kinds of projects like Swoole (gives you a runtime similar to Go) and ReactPHP (runtime similar to Node) and https://github.com/krakjoe/parallel for lower level concurrency. There's also pthreads https://www.php.net/manual/en/book.pthreads.php But again most of these aren't necessary for most apps because of PHP's request-response model. Useful for one-off services though.

> typed function parameters

Completely untrue. https://www.php.net/manual/en/functions.arguments.php#functi...

> no method/function reference

You do those like this: [Example::class, 'someFunction']

I hate it when people write such blatantly misinformed comments. Sigh.

Re: PHP 8: Before and After

#294

Earlier quoted context omitted.

> It's becoming kind of an Enterprise language It tried for decades to be one with Doctrine, Symonfy and co, trying to copy the worst of Java EE with every single possible design pattern implemented in these frameworks, XML configuration files and co... The problem is no generics, no private packages makes PHP OO a horrible mess compared to Java (or C#).

Symfony supports YAML files too since... almost forever.

actually in future versions symfony will move mostly to php based configs instead of yamk, xml. at least parts of internal configs which were xml now are rewritten to php

Re: PHP 8: Before and After

#295
post #267

Earlier quoted context omitted.

If you mean persistent databases or caching like Redis, it's still much easier to accidentally reference a global pointer due to a programming error than accidentally put something in a cache store. All systems need some sort of persistence, this is true for other languages as well.

No, I'm talking about the kind of thing that provides a `Context`-like object that allows the application developer to share memory between requests.

Like others have mentioned, there is no such thing in PHP. Each request is handled individually from a blank slate and the context is destroyed when the request finishes.

Re: PHP 8: Before and After

#296
post #230

One of the underappreciated pros of php for web development is its execution model, it's fault tolerant by default and shares little memory across requests. This kind of makes sloppy programming far more tolerable in php than in other platforms. In effect this has an impact on performance but it also helps in ensuring that a bad request can't blow out the whole application from serving other requests like is common i…

> this has an impact on performance And yet, I find that PHP apps tend to be quite performant, compared to say Java or Rails (I don't know about node, maybe not compared to node). But I'm not a PHP developer, this is just my impression. And the complaints you hear about PHP, I seldom hear performance. No?

It varies considerably. If you write the kind of simple PHP pages which gave it that reputation, it's almost always going to be limited by I/O. If you use a framework which encourages enterprise-style apps with hundreds of includes and object hierarchies which would make a J2EE developer weep, even the opcode cache won't be enough to get back to that spot. I don't follow it enough to see if this passing away niw but there was definitely a sizable chunk of the community which really thought that Real Programmers™ didn't write simple code.

Re: PHP 8: Before and After

#297
post #178

Earlier quoted context omitted.

I haven't found any good arguments against PHP in the comments here, just pure hate. Let's name a few of the arguments people are making: 1. Its variables start with $ and that is ugly: I mean, come on, I won't even entertain this bigotry. 2. It used to be better before: This is just pure nonesense, before OOP PHP wasn't good to create any big and well-structured application, it is ironic because most of the bad opin…

> 1. Its variables start with $ and that is ugly: At the very least it seems nonsensical and cargo-cultish: As a non PHP-er, what is the actual purpose of $? In Perl, it indicates variable context (for better or worse, there's more than one, so it has to be indicated somehow ). In shell, it indicates the substitution of variable name by its value. In PHP...I draw a blank. It really seems like an "I wanted my language…

It's actually slightly wrong to just say "variables start with $". It's more like "$ dereferences a string":

  $foo = "I am foo\n";
  $bar = "foo";
  echo $$bar;
This is in the documentation under "variable variables" [0]. This also lets you create dynamic function names:

  function run_foo() {
      echo "I'm a foo\n";
  }

  $method = 'foo';  
  $picked = "run_$method";
  $picked();
[0] https://www.php.net/manual/en/language.variables.variable.ph...

Re: PHP 8: Before and After

#298

Earlier quoted context omitted.

That's what baffles me with PHP. Instead of building on PHP's unique capabilities, they try to become more like Java. When PHP was and is quite successful as server-side language for HTML templating, rooted in embedded PHP triggered from SGMLish processing instructions in otherwise static HTML. It's only that they made such a hack job without context-dependent, HTML-aware escaping, making it a primary vector for inje…

It was because every developer in the West was taught that inheritance based OOP was the one thing to rule them all. And that unfortunate school of thought created the Java mythos that spread to many languages, not only PHP, eg JavaScript (everyone trying to write inheritance based OOP in a prototype based language). Few years ago the mythos changed somewhat to every programming language should be functional. Thus it…

> It was because every developer in the West was taught that inheritance based OOP was the one thing to rule them all. > > And that unfortunate school of thought created the Java mythos that spread to many languages, not only PHP, eg JavaScript (everyone trying to write inheritance based OOP in a prototype based language)

I don't think it's as simple as OOP being bad but rather the culture of complexity that everything had to have deep object hierarchies, layers of indirection and runtime configuration, etc. If you write Python, JavaScript, PHP, etc. classes which don't try to follow the enterprise Java style and only pay for the complexity needed by the problem domain the results are fine.

I think a large part of it was that many people learned not OOP but how the Java standard library and J2EE worked, and internalized the idea that you were trying to produce a reusable abstraction for the entire stack which could be used by unrelated projects without realizing how expensive that kind general framework development is.

Re: PHP 8: Before and After

#299

Earlier quoted context omitted.

> this has an impact on performance And yet, I find that PHP apps tend to be quite performant, compared to say Java or Rails (I don't know about node, maybe not compared to node). But I'm not a PHP developer, this is just my impression. And the complaints you hear about PHP, I seldom hear performance. No?

if you do something in a naive way, PHP performance can tank pretty severe - but that's more down to the developer implementation rather than a shortcoming of the language itself

I fully agree, but I think this is an issue in most languages (not counting compiler optimizations)

Re: PHP 8: Before and After

#300
post #267

Earlier quoted context omitted.

If you mean persistent databases or caching like Redis, it's still much easier to accidentally reference a global pointer due to a programming error than accidentally put something in a cache store. All systems need some sort of persistence, this is true for other languages as well.

No, I'm talking about the kind of thing that provides a `Context`-like object that allows the application developer to share memory between requests.

Write to a database or file?
Post reply on HN