Live data from Hacker News

What's New in PHP 8.1

stitcher.io

1–10 of 112 posts

Re: What's New in PHP 8.1

#2
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))));

Re: What's New in PHP 8.1

#3
"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.

Re: What's New in PHP 8.1

#4

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…

Good to have this in PHP. It's called "spread" in JavaScript.

Re: What's New in PHP 8.1

#5
post #4

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…

Good to have this in PHP. It's called "spread" in JavaScript.

and a myriad of other names in schemes and ml dialects

Re: What's New in PHP 8.1

#6
post #3

"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.

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.

Re: What's New in PHP 8.1

#7
post #4

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…

Good to have this in PHP. It's called "spread" in JavaScript.

I always think of it as a variadic parameter, and I think spread has a little magic behind it.

Re: What's New in PHP 8.1

#8
post #3

"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.

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.

Re: What's New in PHP 8.1

#9
post #8
post #3

"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.

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.

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...

Re: What's New in PHP 8.1

#10
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.
Post reply on HN