[HN Gopher] What's New in PHP 8.1
       ___________________________________________________________________
        
       What's New in PHP 8.1
        
       Author : hypomnemata
       Score  : 79 points
       Date   : 2021-01-29 16:48 UTC (6 hours ago)
        
 (HTM) web link (stitcher.io)
 (TXT) w3m dump (stitcher.io)
        
       | svnpenn wrote:
       | I recently killed all my PHP code in favor of Go.
       | 
       | What finally convinced me is the Go package system. I like that
       | Go has a builtin package manager, while I dont think PHP does. I
       | know about Composer, I just wonder. After all these years, why
       | hasnt PHP incorporated a builtin package manager?
        
         | nolok wrote:
         | Your question is weird, like a solution in search of a problem.
         | 
         | So let me ask, what problem does composer have that you hope to
         | see a builtin package manager solve (at the cost of losing its
         | own dedicated team) ?
        
           | skissane wrote:
           | Who knows, maybe one day Composer will be bundled with PHP.
           | (And bundling Composer with PHP wouldn't necessarily mean
           | that Composer would lose its own independent dev team.)
        
         | jspaetzel wrote:
         | PHP developers have been very successfully using Composer for
         | many years. It's actually quite nice having the package
         | management decoupled from the language, there's fewer chances
         | for breaking things between upgrades which helps slightly with
         | long term support.
         | 
         | Congrats on getting a package manager for Go!
        
         | stunt wrote:
         | As long as you got a strong package manager and good ecosystem
         | around it everything is ok. Many languages don't have built-in
         | package manager.
        
       | Minor49er wrote:
       | Array unpacking is going to help make a lot of coding situations
       | more concise. There isn't a direct comparison in the article, but
       | from what I understand, something like this:
       | $array = array_merge(["a" => 0], $array1, $array2);
       | 
       | could be replaced with this:                 $array = ["a" => 0,
       | ...$array1, ...$array2];
       | 
       | It seems small here, but anything that stops devs from having to
       | nest a bunch of array*() calls in PHP is an excellent change. I
       | don't know how many times I've come across code that does
       | something like this:                 $array =
       | array_values(array_unique(array_filter(array_merge($one, $two,
       | $three))));
        
         | reactspa wrote:
         | Good to have this in PHP. It's called "spread" in JavaScript.
        
           | nkozyra wrote:
           | I always think of it as a variadic parameter, and I think
           | spread has a little magic behind it.
        
           | agumonkey wrote:
           | and a myriad of other names in schemes and ml dialects
        
       | iso8859-1 wrote:
       | What is the idiomatic way to have data in an enum in PHP, aka sum
       | types? Sum types in languages like Rust or Haskell or OCaml can
       | have data associated with them. You'll get an error before
       | runtime if you assume a field is available when it isn't.
        
         | duckerude wrote:
         | That would probably be union types[0] (or plain old dynamic
         | typing) with checks like `is_null($val)` and `$val instanceof
         | Type`.
         | 
         | Offline typecheckers (not included with PHP) can analyze the
         | control flow to prove that any invalid types have been ruled
         | out when an operation happens. It's not nearly as principled as
         | proper sum types, but it works alright in practice.
         | 
         | PHP's upcoming enums are simple values, more like C's enums
         | than Rust's enums.
         | 
         | [0]:
         | https://www.php.net/manual/en/language.types.declarations.ph...
        
       | 29athrowaway wrote:
       | I do not think PHP is a good language to use in a project.
       | 
       | - dev recruitment is hard.
       | 
       | - dev retention is hard.
       | 
       | - hard to find people that write clean, modern, performant PHP
       | 
       | - it is PHP, with everything that it entails. It does not enjoy
       | the best reputation as a language.
        
         | tored wrote:
         | It is true that PHP has a bad reputation and that effectively
         | limits number of potential skilled developers.
         | 
         | Number of available developers is still high but it could be
         | even higher if it had the same successful propaganda as
         | JavaScript or Python.
         | 
         | There is nothing in the language itself that should stop it
         | from competing with any general purpose language, not anymore.
         | 
         | I think this is the next important step for PHP, have
         | charismatic & humorous evangelist like Douglas Crockford.
         | 
         | Crockford's missionary work was done during a time when
         | JavaScript was in a big expansion because everyone wanted to
         | write single page applications.
         | 
         | But today there is huge JavaScript fatigue and more and more
         | developers have start to realize that server side rendering is
         | (back to) the future for most of the traditional web,
         | especially in a time where time to market has become even more
         | important.
         | 
         | The constant churn of the JavaScript realm have now reached
         | epidemic levels, a massive & relentless wave of deprecated and
         | unsupported projects sweeps over every organization. Somewhere
         | right now some poor developer inherits a Angular 1.1 project
         | built with gulp.
         | 
         | I think also there have been a shift in regards to fullstack
         | developers versus frontend & backend developers, many companies
         | have woken up to disastrous idea of splitting frontend &
         | backend developers into separate teams and now merging them
         | again, as result the fullstack developer becomes more
         | important. PHP is in my opinion best fullstack web platform you
         | can use.
         | 
         | Say after me, No more build steps for rendering a paragraph, no
         | more unhandled Ajax errors, no more REST JSON apis with only
         | the frontend as consumer, no more reimplementing the database
         | schema in JavaScript, no more asynchronous state rendering on
         | the same page. <Insert Braveheart meme>
        
         | jraph wrote:
         | Do you have evidences to back up these claims?
         | 
         | Many PHP projects are successful. WordPress, Nextcloud,
         | Wikipedia, Facebook...
         | 
         | Something about it must be right.
        
           | adevx wrote:
           | I think the OP has a fair point. I could be way off but I
           | feel few developer get excited about working on PHP projects.
           | I jumped ship to Node.js around PHP 5 and haven't enjoyed
           | working on PHP code bases ever since. I think this in part
           | could be due to TypeScript, giving much more confidence in
           | refactoring and moving a project forward. The massive npm
           | module ecosystem is probably also a major factor. The fact
           | that WordPress and Facebook use PHP is more historic then
           | being exemplary for it being an excellent solution.
        
         | blahyawnblah wrote:
         | None of your list says anything about the language. It says
         | more about the companies hiring.
         | 
         | What does PHP entail??
        
           | 29athrowaway wrote:
           | Erlang, Haskell and OCaml are excelent languages. But good
           | luck assembling a team that can use those languages. e.g.: 30
           | developers in 1 year.
           | 
           | And those languages are pretty popular compared to others.
           | 
           | The programming language you use is a important factor when
           | it comes to scaling your team (and your product, and your
           | business).
           | 
           | I do not want to start a bikeshedding holy war. The reference
           | implementation of PHP is pretty inferior to that of other
           | scripting languages such as Ruby, Python, Julia and Node.
           | There are other implementations that are better but come at a
           | compatibility cost.
        
             | krob wrote:
             | I don't agree with this. I'm not going to get into a holy
             | war, but I soundly disagree that it's inferior. Any
             | C/C++/Java programmer can become productive with php very
             | rapidly. The callstacks are familiar to programmers, the
             | language continues to get faster & faster as older legacy
             | structures are replaced with smarter data-structures
             | allowing for JIT optimizations.
        
         | acomjean wrote:
         | PHP is incredibly easy for any competent programmer to pick up.
         | If you know C/Java you can get into php pretty easily.
         | 
         | If you use structured projects, (symfony) in our case its much
         | easier to use and maintain.
         | 
         | We have older Java and Perl and Python to maintain. Its much
         | harder to get those up and running.
         | 
         | The startup I worked at 8 years ago used PHP and got bought. I
         | think the ability to get into it quickly and get something
         | running is underrated frankly.
        
         | krob wrote:
         | Dev recruitment is hard to find php developers? wtf are you
         | smoking? I think a lot of this is highly dependent on where you
         | are. My guess is you mostly deal with non php languages?
        
           | pantelisk wrote:
           | > dev recruitment is hard.
           | 
           | No way. It is pretty easy. To be fair it is harder in the Bay
           | Area than let's say Europe, but it is still a non-issue.
           | Also, the language is extremely easy to pick up, everyone is
           | able to understand the code. This week for example I 've had
           | an ios dev that is using Obj-C/Swift just dig into the code
           | themselves to get clarity on an endpoint's execution.
           | 
           | > dev retention is hard.
           | 
           | Never really had an issue there.
           | 
           | > hard to find people that write clean, modern, performant
           | PHP
           | 
           | This also has not been a problem in the past few years. For
           | context, I 've had multiple devs excited and pushing to start
           | using new PHP8 features, already (and I had to be the boring
           | one and ask to wait for hotfixes, a version .1 or .2 and see
           | how stable and secure 8.x is first).
           | 
           | > It does not enjoy the best reputation as a language.
           | 
           | This is true. I 've met people who refuse to even look at PHP
           | code, even though they are paid to do so (they might even
           | refuse at the detriment of their peers). I 've never seen a
           | "this is beneath me" attitude with any other tool or language
           | before. (except perhaps the hate SQL databases got in
           | 2015-2016) So yeah, the hate runs deep.
        
       | tyingq wrote:
       | _" New array_is_list function"_
       | 
       | I use PHP a fair amount, but this is one area that irks me. PHP
       | arrays can be arrays, lists, and hash maps. PHP obviously copied
       | some of Perl's features, and I never understood why hashmaps and
       | arrays weren't different types, as they are in Perl.
        
         | nkozyra wrote:
         | I haven't used PHP with regularity since the start of 7.0, but
         | I agree. Having this mushy collection type seems so easy to
         | just replace with [] for arrays/lists and {} for objects/class
         | instantiations by convention.
        
         | thibran wrote:
         | Funny. I almost dislike all of PHP but think that their choice
         | of basic data structure is the one good thing. Computers are
         | getting faster and faster and simplifying programming could be
         | done to a whole new level. Clojure for example has a similar
         | approach. Okay, PHP lacks contracts, but maybe PHP adds them in
         | 20 years when the mainstream understands that they are great.
        
           | kitsune_ wrote:
           | Clojure's persistent collection types include List, Vector,
           | Map, Set and you have namespaced keywords. In general, I
           | don't see how you can compare the approach of Rich Hickey and
           | Clojure to PHP to be honest...
        
           | duckerude wrote:
           | For me it didn't really simplify programming, it just added
           | mental overhead. Every array I used was either strictly
           | sequential or strictly a mapping, and the language did
           | nothing to help me keep track of that.
           | 
           | It also makes some potential niceties impossible. Python can
           | give a special meaning to a negative index into a list,
           | because it can never truly exist, but PHP has to treat it
           | like a key and do a normal lookup.
        
           | ashton314 wrote:
           | I too dislike PHP, but this is one of the things I hate the
           | most: this is like conflating addition and multiplication of
           | types. Arrays and maps have separate use cases and very
           | different trade-offs and PHP gives you no choice in the
           | matter.
        
         | pornel wrote:
         | I love them. Lisp can use lists for everything, and PHP arrays
         | ;)
         | 
         | Thanks to their mixed nature they're very versatile. People
         | even make small DSLs out of them. And they're order-preserving,
         | so they won't inject non-determinism just to smugly teach you a
         | lesson about real hash tables.
        
       | ashton314 wrote:
       | > array_is_list
       | 
       | This is a stupid solution to a stupid problem. Defaulting to weak
       | typing has enough problems, but _changing the behavior of your
       | data structure based on its contents_ is next-level pain. I used
       | PHP for a few years at a student dev job and I can't count how
       | many times this conflation wasted my time and introduced various
       | bugs.
       | 
       | If PHP wants to become more respectable as a PL, it has got to
       | break that out into _real_ arrays (a linked list might be
       | acceptable under certain circumstances) and maps.
        
         | [deleted]
        
         | FriedrichN wrote:
         | > I can't count how many times this conflation wasted my time
         | and introduced various bugs
         | 
         | Could you give examples of this? I'm of the opinion PHP could
         | use more strictly typed arrays/lists, but I haven't run into
         | any issues with PHP arrays myself.
        
       | mike503 wrote:
       | This is really making what used to be an easy to read, easy to
       | learn language a lot less of that. Some of us still don't use
       | IDEs and are okay with more thoroughly defined code that is
       | readable.
       | 
       | If people are so gung ho on adding in syntax hacks, shortcuts,
       | etc, they seem to be bringing ideas from other languages and why
       | not simply continue to use that other language? PHP seems to be
       | looking more and more like Go or JS to me now. Anyone want to
       | start a fork called "PHP Classic"? :)
        
         | spillguard wrote:
         | Is that what PHP should strive to be - the "most easy to read
         | language available"? What does that even mean, just that there
         | isn't any shorthand?
         | 
         | No one is forced to use the new syntax, it's just different
         | tools in the tool belt.
        
         | cyberCleve wrote:
         | Are you saying you do not use IDEs? What is your rationale for
         | that decision?
        
           | mike503 wrote:
           | Never have, never got into it. Edit directly on shell. Muscle
           | memory, creature of habit. :) also still only write
           | procedural PHP myself.
        
         | [deleted]
        
       | AdrianB1 wrote:
       | I am not a developer, but I use PHP a lot for scripting and
       | personal automation including small web apps with SQL backend. I
       | found PHP 7 to be a great improvement over 5.x, but with 8 I
       | skipped every single new thing they brought. I can use PHP 8.1 in
       | PHP 7.4 compatibility mode, but I find the features in 8.1 making
       | the language less readable and less logic; for example, 3 dots
       | become part of the language syntax? What is next, emojis as
       | operators? Secret gang hand shakes as functions?
        
         | FriedrichN wrote:
         | Fun fact: failure to implement unicode is the reason we never
         | got a PHP6. So we're safe from emojis for at least a while.
        
         | deergomoo wrote:
         | ... was already syntax, for variadic parameters. Re-using it
         | for unpacking makes perfect sense IMO.
        
         | Sniffnoy wrote:
         | What's wrong with ellipsis as syntax? Plenty of languages have
         | some sort of ellipsis (either 3 dots or 2) as syntax. See for
         | instance
         | https://en.wikipedia.org/wiki/Ellipsis#Programming_languages
         | and
         | https://en.wikipedia.org/wiki/Ellipsis_(computer_programming...
         | . JavaScript/TypeScript also uses it in a similar way to PHP.
        
       ___________________________________________________________________
       (page generated 2021-01-29 23:01 UTC)