One thing I still love about PHP is that it's so easy to deploy. No need for fancy Amazon Web Shmervices, no need for Jamstack jumping through the hoops. Just find any host that supports PHP, upload your file, and done.
What's New in PHP 8.1
101–110 of 112 posts
Re: What's New in PHP 8.1
#102Earlier quoted context omitted.
> changing the behavior of your data structure based on its contents PHP does no such thing. There is one array type with one behaviour. There is no distinction between different kinds of arrays in the language.
Doch. Try piping the result of array_filter to array_map sometime. You can’t do it without an intermediate call to array_values first because the result of passing a list to array_filter does not behave like a list anymore: it operates strictly like a map and cannot have map called on it. (Oh the irony!)
Re: What's New in PHP 8.1
#103Earlier quoted context omitted.
Doch. Try piping the result of array_filter to array_map sometime. You can’t do it without an intermediate call to array_values first because the result of passing a list to array_filter does not behave like a list anymore: it operates strictly like a map and cannot have map called on it. (Oh the irony!)
The caveat I'm aware of with array_filter is that it can leave gaps in the indexes, but having an array like that doesn't break array_map. The output from it will just have the same index gap as the input.
$ php -r 'var_dump([1, 2, 3, 4]);'
array(4) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
[3]=>
int(4)
}
$ php -r 'var_dump(array_filter([1, 2, 3, 4], function ($x){return (bool)($x % 2);}));'
array(2) {
[0]=>
int(1)
[2]=>
int(3)
}
$ php -r 'var_dump(array_map("strval", array_filter([1, 2, 3, 4], function ($x){return (bool)($x % 2);})));'
array(2) {
[0]=>
string(1) "1"
[2]=>
string(1) "3"
}Re: What's New in PHP 8.1
#104Earlier quoted context omitted.
Dynamic typing is a trade off, one that requires some explicit type checking in some situations. It doesn't make it a stupid solution or a stupid problem. If you validate and conform your types at program edges it's rare you ever really need to do type checking. That is, a properly structured PHP application has all the benefits of dynamic typing and few of the problems that static type checking supposedly eliminates…
I like dynamic typing: most of my work is done in untyped Racket or Elixir. Weak typing is fun, but can be frustrating. My issue is that this single data structure functions like a list in some cases, and a map in others. Try piping the result of array_filter to array_map sometime. You can’t do it without an intermediate call to array_values first because the result of passing a list to array_filter does not behave l…
Re: What's New in PHP 8.1
#105One thing I still love about PHP is that it's so easy to deploy. No need for fancy Amazon Web Shmervices, no need for Jamstack jumping through the hoops. Just find any host that supports PHP, upload your file, and done.
That's not just PHP, you can use anything that supports CGI, and lots of shared hosting have pre-installed Perl and Python as well as PHP.
Re: What's New in PHP 8.1
#106Earlier quoted context omitted.
You dont need to sign up to multiple sites and maintain multiple accounts. You don't even need to use Git or lambda functions. That's what I mean by jumping through hoops. With PHP I just upload the file and done. Nothing beats this simplicity. For simple stuff, it's my favorite.
You need rent the hosting, login, access control panel, retrieve FPT authentication, then upload stuff. For JAMStack, just git push and done. I don't see PHP is easier ;)
Re: What's New in PHP 8.1
#107Earlier quoted context omitted.
Almost anything can be simulated in any other data type, often with poor performance and easy bugs. If a programmer use lists in lisps where vectors or hash tables are more appropriate, he is doing something wrong. Likewise, simulating arrays in hash tables, which is what PHP expects one to do, is a very bad idea. Bash lacks multidimensional arrays, but it does have hash tables, so some programmers resort to simulati…
The reality of most of programming I've done is that in 98% of cases you deal with data structures that are sufficiently small for performance not to matter much on modern hardware. If you do need to deal with data structures that are quite large (i.e., take GBs of memory), perhaps PHP is not the right language.
Re: What's New in PHP 8.1
#108One thing I still love about PHP is that it's so easy to deploy. No need for fancy Amazon Web Shmervices, no need for Jamstack jumping through the hoops. Just find any host that supports PHP, upload your file, and done.
That's not just PHP, you can use anything that supports CGI, and lots of shared hosting have pre-installed Perl and Python as well as PHP.
Re: What's New in PHP 8.1
#109What 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.
This isn't exactly a sum type. Sum type is basically a Union, a proper algebraic data type, and PHP doesn't have algebraic data types (although, even before type hints it was a relatively common practice to "implement" them via PhpDoc... horrible, I know). Enum is basically a bunch of constants, for all practical purposes. There were enums in Java for a long time, long before languages with more-or-less proper type s…
Were we? Java is literally the language that drove me to hate types and prefer python for a few years, until I learned Haskell..
Re: What's New in PHP 8.1
#110I 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.
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,…
> Somewhere right now some poor developer inherits a Angular 1.1 project built with gulp.
That hit hard. I was reassigned to an old project from 5 years ago with an archaic framework, to refactor all the code to the "new shinny JS framework". Ironically, I was in the team that built it 5 years ago. It is dreadful. Rinse and repeat.
I feel like I'm doing something wrong when I advocate against projects that need 50,000 files and a 2-minute build when you could just do with HTML/CSS, native JavaScript and a simple CRUD backend.