Hacker News new | past | comments | ask | show | jobs | submit login
PHP 7.4 (php.net)
288 points by velmu on Nov 28, 2019 | hide | past | favorite | 184 comments



While everyone else (well, me) have their attention on the hippest, newest languages PHP has been steadily improving, getting faster, and still runs a lot of the largest web properties. It wouldn't surprise me if before long PHP can be compiled to native binary* complete with a memory efficient, non-blocking web server and performance approaching what Go and dotNetCore can achieve... and the option to emit a "normal" PHP web app that can run anywhere if you don't need Facebook-level performance from it.

*I realize HipHop PHP did this already but it doesn't have it's own baked-in web server afaik. I'm thinking along the lines of compiling down to something small and fast to be deployed to K8S clusters without needing containers for Apache or nginx as part of the setup.


PHP doesn't really want to do the web server part. PHP provides a request based (stateless or "Serverless before there was serverless") container for script execution and leaves the server part to some other program. Doing proper HTTP serving involves many things others have already done and where others will inovate. Dealing with security (SSL/TLS certificates and ciphers), virtual hosts, access permissions, HTTP protocol versions and so on is lots of work PHP developer leave to experts at Apache, nginx or whatever comes next.

Sure - one could do what many folks in other environments are doing: node.js or go developers often implement a simple API endpoint and use a reverse proxy (nginx or something) in front of it for interacting with the outside world, but fpm is the more specialized protocol for that.

Then again PHP is driven by people contributing. If some folks contribute according infrastructure and push for it I could be proven wrong. :)


Actual webserver may not be useful but it would open the door to out of the box support for servicing websockets which currently requires using things like Swoole to achieve in PHP.


Websockets are nice, but don't really fit into PHP's architecture around short lived requests.

Sure, for most parts PHP can handle that, but for long running things some I/O event based context switching typically is more efficient and in a few error cases PHP deferrs cleanup to "request shutdown" which might be a while out with websockets.

In the end PHP is focussed on one role (serving "normal" HTTP requests in isolated contexts quickly) and other technologies do other things better. And I think focus is a good thing.

Then again: PHP is open and does whatever the contributors want it to do and I myself am not actively contributing much anymore :)


"it doesn't have it's own baked-in web server afaik"

It does, actually: hhvm -m server -p 8080

Uses proxygen.

Proxygen is pretty cool, actually. Even does http/2 & https, and is suitable for production use. I'm somewhat surprised nobody's done the work to link it with PHP, Perl, etc, to provide what node.js does for js.

Edit: Also, on compiling PHP, there's a pretty good start here: https://github.com/ircmaxell/php-compiler/blob/master/README.... The FFI functionality in PHP 7.4, plus the internal use of an AST in php7.x, are what made it possible. Missing lots of functionality, but a neat proof of concept.


php also has one: php -S localhost:8000 -t foo https://www.php.net/manual/de/features.commandline.webserver...

since 5.x (not production ready tough)


If you use Swoole, you can implement a performant server in a async Node fashion with your code, PHP and Swoole extension:

https://www.swoole.co.uk/docs/modules/swoole-http-server-doc


Unrelated to the topic but why the fuck do those people need to set 600 different cookies?


Someone whose name I forgot (paul something ps: paul biggar) made a thesis on the uncompilability of PHP, but that was few years ago, maybe with the addition of typed annotations it's gonna be possible to get a bit of it.


That doesn't scale. You want a high performance web server in front of a farm of php app servers.


A lot of those large web properties are going to be using old versions of PHP. Newer versions have breaking changes that make upgrading a large codebase difficult.

To these companies, PHP 7 is a hip new language that they're not using.


> A lot of those large web properties are going to be using old versions of PHP.

Is that true? PHP 5.6 and 7.0 were EOL'd in 2018, and acording to data at https://blog.packagist.com/php-versions-stats-2019-1-edition... the use of PHP 7 and later is ~90%. Web properties like DreamHost have supported PHP 7+ for years, and have deprecated versions before 7.1.

> Newer versions have breaking changes that make upgrading a large codebase difficult.

The documentation on this is pretty good[1], and there's some nice tooling that can help[2]. I wouldn't say that I've migrated "large" codebases, but FWIW in my limited experience this hasn't been particularly onerous.

[1] See https://www.php.net/manual/en/migration70.php and related appendices [2] https://auth0.com/blog/migrating-a-php5-app-to-7-part-three/


I think a lot of places stick with whatever PHP version comes with the Linux distribution they use, only use Linux distributions with long term support, and only update to a later release of that distribution when the one they are on is about to go out of long term support.

For Red Hat, that means there are places still on RHEL 5, 6, and 7, which is going to put them PHP at 5.4.

It looks like Ubuntu 16 is the oldest Ubuntu still under support. That had PHP 7.0. Ubuntu end-of-life (when they stop getting security updates) are later than end of support. Ubuntu 14 EOL is April 2022. That has PHP 5.5.9.

Debian 8 has long term support until June 2020, and PHP 5.6. Debian 9 has LTS to June 2022, and PHP 7.0.

For those who are on the latest LTS or equivalent:

RHEL 8 has PHP 7.2.

Ubuntu 18 has PHP 7.2.24

Debian 10 has PHP 7.3.


Stats from packagist.com are biased towards newer versions. They are coming from composer users, and if you are using composer, you are a lot more likely to be using more or less up to date practices and relatively new version of php. There are millions of legacy projects and wordpress sites that have nothing to do with composer, and they are running on old versions of php much more often.


Earlier this year I spoke to a team on PHP 5.1 - EOL was 2006! They have a massive PHP 4 style codebase, all in-house (no framework), a team of devs that knows it intimately and doesn’t want to leave because they have no job prospects. Sadly, judging by emails I get, there are a lot such teams operating in small towns.


> Sadly, judging by emails I get, there are a lot such teams operating in small towns.

I can believe that, even if I don't understand the mindset. Unless they're ready to retire, you'd think they'd want to keep their toolboxes current.


They must struggle to hire new devs, meaning no one comes in and tries to push the team onto newer versions


we upgraded a 100k lines PHP 5 codebase to PHP 7.1 in a month. if your php 5 code wasn't using any deprecated extensions (like the old mysql extension) upgrading is really easy. there are static analysis tools that spot the potential problematic code so you don't need to do it by hand. from that point on if you got any automation testing or unit tests you can have a good level of confidence that your upgrade was a success.


Agreed, we wanted to upgrade from 5.9 to 7.1 and once we got it working we fired up docker with 7.3 and it just worked. Glorious


Sorry, what is 5.9? You meant PHP 5.6?


Yes! Unsure where I got 5.9 from


Migrated a few million lines of code spread over a few apps in a couple of days to php 7. Most of the time was spent setting up docker and migrating unit tests. There were literally zero code issues. Those are properly written and engineered apps written on top of proper frameworks as any professional would write them. There is another app that depends on a php 5 library that's still running on php 5 now, three years later. So the upgrade situation is extremely easy and simple if your code isn't total shit. With shit code, the migration is the least of one's worries.


What percentage of old PHP code do you think is well-written with good unit test coverage?


Go after PHP has been therapy to me.


i dreaded the upgrade to php 7.2 in some 10 year+ old apps, i thought too many things would break. Turns out it was easier than expected, and it's faster too!


In my experience I only had real problems with projects built on outdated frameworks, like cake 1.3, because the framework was not compatible with php7, and upgrading to latest version of framework meant basically a full rewrite.

A few other old sites, even relatively large ones, that were built from scratch or on homegrown CMS years ago, only took some minor fixes and mostly were up and running in couple of hours, some even worked right away without any issues.


The most interesting thing about PHP is it is, AFAIK, the most community-driven language today. Go, Python and JavaScript are all under heavy influence of Google, C#, VB.NET and TypeScript is Microsoft's turf, Java is Oracle's, Rust and WebAssembly - Mozilla's.

С and С++ are holding their grounds, but they are more and more niche today. Facebook tried to domesticate PHP, but failed spectacularly. So it looks like PHP is most democratic and liberal programming language of today) I am glad it's getting steadily ahead.


Rust has a lot of core team members that no longer work at Mozilla, so this isn't really true today.

Also, C and C++ are some of the most widely used languages in the world. I wouldn't call them niche.

Edit: according to the TIOBE C/C++ are ranked higher than PHP


... and it's been that way for a long time; we operate on consensus, and in 2014, non-Mozilla folks were added to the core team.

Today, it's extremely diffuse; there are ~200 people on the various teams that hold decision making power over the project, and only like six are Mozilla employees. The core team has 3 Mozilla employees and 9 people total.


Thank you for those numbers, it confirms my intuitive conclusuion: 1/3 of core team is a significant influence.


Sure, there’s no doubt that Mozilla has influence. What’s important to me, personally, is that they cannot dictate what happens. And we have non-theoretical examples of where that’s the case; Servo would have really liked some form of inheritance to model the DOM, but the team overall said no. Also, note that the core team doesn’t make most of the decisions, unlike core teams of other languages. They also have a minority of representation on the language team as well.

And, as someone who was involved before, during, and after working for Mozilla, Mozilla just plain doesn’t have interest in really guiding Rust development. If anything, it’s diminished over time, after all, when Rust started, it was sponsored by the CTO and a director, both of whom eventually left, but also that thought it was important for Rust to be as independent as possible.


Google does not care that much about Python, at least not when I was working there. I would certainly not mention it together with Go.


Google does not care about python is not the same as Python being controlled by a small no of Googlers. I don't know much about whether that is true or not though.


Aren't Elixir and Ruby primarily community driven too?


I know almost nothing about Elixir short of there is a language with this name and it related somehow with Erlang. It's a very niche language/VM good for high-load realtime events processing, thus only noticable project on Elixir is Discord (and on Erlang - WhatsApp, Facebook Messenger and RabbitMQ, which kinda gives a hint too).

Ruby is a brilliant language (pun intended), but from where I am (web- and mobile software development for last ~20 years) it seems to be steadily declining. Headhunters having a hard time looking for Ruby devs now.


> Headhunters having a hard time looking for Ruby devs now

Sounds like the supply is lower than the demand for Ruby devs, which sounds to be like the opposite from "steadily declining".

Also, one should look further than usage when it comes to evaluating a language.


I see your point. My point is that to be called "community driven" the language should be relatively popular. Otherwise there would be an absence of community on the first place.

IMO Ruby/Rails became legacy tech. Are you aware of any fresh significant projects on Ruby?


I thought "community driven" also meant that the language itself was primarily developed by the community and not by someone with monetary interests. And in that regard both Ruby and Elixir are very much community driven — and both regularly see new releases too.

And in terms of numbers. If you look at e.g. number of repos on GitHub with at least 10 stars[0], Ruby comes in as #7 ahead of C# (#8) and Go (#9) and faaar ahead of Rust (#17).

Interesting side-note. C and C++, which you called "niche", clock in at #6 and #5 respectively.

[0]: https://github.com/oprogramador/github-languages#10-stars


This is because Rust is a very young language, and C and C++ are very old. Number of projects on GitHub is more proportional to language's age than to it's current popularity. To check popularity we have to take a first derivatve of these numbers over time.

Thanks for the lunk though, it does shows some interesting stats.


I don't think age is that much of a factor because TypeScript also places higher than Rust and is two years younger, not to mention Go and Rust are only a year apart but they're pretty far apart on the chart.

More data here: https://githut.info/


You may think of TypeScript as a modern dialect of JavaScript. I don't think it applies to pair Java-Kotlin though.


By that account isn't Rust then a modern dialect of C++ and Go of C?


(That web page has data from 2014)


PHPs feature development are driven by a relative few “core” people who understand C, and who seem intent (despite what the larger community wants) to keep making PHP more and more like Java.

IMO Some stuff is great of course but things like their planned JIT additions (which effectively make PHP faster at calculations, which few people use PHP for) and type enforcement (in a dynamic language with no compile step) seems to really miss the mark of what makes PHP great and so widely usable.


> keep making PHP more and more like Java.

I know this is meant as an insult but it's a poor one. There are programming languages features out there that are good on their own merits and PHP is incorporating those features. If they also happen to also exist in Java, or C++, or Haskell then they do. Adding those features might make a language more like X because X also has that feature but that doesn't mean it's the goal.

In many ways PHP does things better than Java by virtue of having hindsight on how those features exist in other languages. The way PHP handles nullable types is better than both Java and C#.


PHP feature development is driven by a rather considerable commitee of core devs and representatives of major frameworks and libraries. All features are undergoing a voting procedure.

PHP JIT is intended to reduce latency and large codebase start-up delay, two biggest problems of modern PHP as for me. It's not about calculations.


It will also help with calculations, maybe the intention is to grab some of python's share.


That would be a very long shot IMO. But we'll see eventually.


What would you like to see instead improvement wise? The typing features are optional, so everything that makes PHP simple to use is still there and available.

I have some patches to improve the DOM API extension for example, simplify its usage which would make it much simpler to use.


> keep making PHP more and more like Java

I have not need to create a class to encapsulate a GET request parameter in PHP. In Java it was common the last time I used it.


Ruby?

Also, why do you say that Python is controlled by Google?


See above: Ruby is good, but it's on decline and IMO soon going to be a niche legacy language for projects too big to rewrite, like Github and Gitlab.

Python was influenced by Google and that influence is hard to wear. Until now Python is definitely not community-driven. Also, look at this version 2/3 snafu.


Probably because they employed GvR from 2005 to 2012.


Yeah, but 2012 was 7 years ago.


And then Dropbox.


The praise for arrow functions is surprising. They don't enable anything new and their feature - saving a half dozen characters - comes with the cognitive cost of tracking how both types of anonymous functions work and their subtle differences in behavior. It's not worth that price.


I am diving back into node lately and it's really annoying to decipher the async and promises styles that are peppered with different anonymous function styles.

I too stick to the most explicit version (function($foo)).

It's the same for command line arguments, I have an easier time remembering words (--preserve-permissions for instancem --volume, etc.) than letters if I don't use the interface enough.


This is a problem in a lot of programming languages nowadays; they borrow features and syntax from other languages without those new features superseding others, and without providing a mechanism to force one syntax over the other.

So that's why we now have half-assed OOP in Javascript, we have Scala which is basically all programming languages ever, etc. Meanwhile, Go is still fighting a lot of requests to add language features, knowing full well the complexity added to the compiler (and more importantly the cognitive overhead for developers).


The art of language design is staying true with its own established patterns. C# fights this battle with primary constructors or combined patterns.


That’s a weird choice. Arrow functions in JS don’t redefine ‘this’ like regular functions, so if you don’t use them, you waste time working around the redefinition.


Also, if you default to `() => ...` for anonymous functions, then you can reserve anonymous `function() { ... }` for the rare times you actually want peculiar `this`. Same reason it's nice to default to `const` so that `let` becomes a signal for the bonus feature of reassignment.


> Same reason it's nice to default to `const` so that `let` becomes a signal for the bonus feature of reassignment.

Code documentation should be clear and concise, not to be deciphered through the code author's take on the meta meaning of reserved words.


No, const inside of a function is a complete waste of time. There has never been a bug that would be prevented by const inside a function.


The big thing enabled by them is not needing to `use ($variable)` to pull a variable in to the scope; however, IMHO, that actually then adds cognitive overhead to the system - I personally will stick to "fully" generated closures.


This is a matter of the situation. For a single statement this can be extremely clear, if the function becomes longer being explicit is nice. And at some length the thing should have a name.

    usort($data, fn($l, $r) => $this->foo($l, $r));
vs.

    usort($data, function($l, $r) use ($this) { return $this->foo($l, $r); });
vs.

    usort($data, [$this, 'foo']);


> For a single statement this can be extremely clear

PHP arrow functions can only contain a single statement and always implicitly return, so that sort of thing is exactly what they're designed for.

Although worth noting with your second example that you haven't needed to capture $this in closures since 5.4, and in fact it is an error to do so now (though I'm not sure when that was introduced).


Using $this was just a simple example where all three cases could easily do the same. Make it $bar :)

Anyways: People are capable of writing loooooong expressions (chaining with && can be good to handle errors from multiple operations in one place (till you have to figure out which specific condition broke)) Thus "single expression" isn't neccisarily short ;)

Anyways: Point is "it can be useful, but developers should think, what they are doing" Perl's "there's more than one way to do it" probably goes too far, but being able to focus on the relevant parts and being able to providing the amount of context needed are good things.


This is the correct answer. Having the option of implicit by-value scope binding is nice. However, I do agree that having the two does add to the overall cognitive cost, albeit not significantly.


I’m with you here. I’d rather have a single uniform syntax for anonymous function.


I've been waiting so long for this day. Finally arrow functions in PHP! Until now it was extremely cumbersome to use higher-order functions such as array_map() or usort() . This is especially true if you're a full stack developer who frequently switches between PHP and JavaScript which has had support for arrow functions for a long time. The hitherto existing anonymous functions are so verbose and it's a real pain to bind all closure variables manually.


It still is cumbersome:

  array_filter(arr, fn)
  array_reduce(arr, fn)
  array_map(fn, arr1[, arr2, ...])
  array_walk(&arr, fn)
Not mentioning additional parameters such as `$flag`, `$userdata` or `$clownshow`.


I think you're the first to point this out. Thank you so much; I just uninstalled php.


Sorry, this wasn't meant for you as a power user, but for the uninitiated who might gets the impression that things are great.


Use eloquent collections instead of vanilla arrays and you'll be much happier


AFAIK, they're just laravel collections - it's (I believe) a separate package you can install which doesn't necessarily have anything to do with laravel eloquent directly. The collections package I'm thinking of might be an unofficial port/extraction of laravel collection stuff. my brother has, I think, started using these in non-laravel projects because he likes the syntax.


I wish they implemented them like in JS without the unnecessary fn().


That would give syntactic ambiguity, since the => operator is also used to separate keys and values in array notation.


Fair, but seems inconsistent to have `fn` instead of `function` like we use for anonymous functions - unless `fn` acts like an alias to `function` now (which doesn't sound like is the case) which wouldn't be as ambiguous for the compiler to figure out


I don't think there's an ambiguity, since the key-value application of that operator only happens inside the array definition or when you do foreach ($x as $k => $v) {}.


There is ambiguity. This was specifically mentioned in the RFC for the feature: https://wiki.php.net/rfc/arrow_functions_v2#syntax


It does if you're trying to make an array of anonymous functions...


Pretty big list of new features: https://www.php.net/manual/en/migration74.new-features.php

Happy to see the proc_open() feature of NOT spawning a shell, and interested in the FFI implementation.


Typed properties and arrow functions are great, but I'm also happy to see the deprecations in this release. E.g. nested ternary operators without explicit parentheses (such use was almost always a mistake). Full list here: https://www.php.net/manual/en/migration74.deprecated.php. Some of the deprecations pave the way for performance improvements in PHP 8.


> nested ternary operators without explicit parentheses

This also seems like a first step toward fixing associativity of the ternary operator, one of the most ridiculous deficiencies of the PHP language.


That's exactly the intent of this change.

"Future Scope: We could make the ternary right-associative in a later release, after it has been an error for a while."

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


Typed properties are well overdue! PHP is almost sexy again...


Only if it can get rid of semi colons.


Praise Jesus Typed properties!!


I’m on the fence about their usefulness. There is a type check on every write, which can lead to major performance losses. Rasmus, the creator of PHP, lamented this in a recent talk.

Using getters and setters already got us type checking external to the class, and is generally good OO practice. Internally I think static analysis on documented types was a good enough solution.


Setters and getters aren’t really object oriented. An object has behaviour, ensuring the inner workings of that object are protected is a good thing _even if_ the inner workings are only ever inner workings. There’s lots of valid and meaningful uses of this functionality.


I'd say that depends on implementation; a lot of languages will only check types on compile. If anything it's a hint for developers, something that their editor will error on if they try and do something wrong.


Looks like they're optional anyway so you're free to do things however you like


isn't the system still going to have to check if a type exists or not anyway, contributing to the potential speed issue?


I'm assuming the check happens at compile time (and therefore cached in the opcache, which you should be using in production anyway)


i would think you'd still have dynamic check - trying to set a string in to an integer type would happen at runtime - you'd be checking before each set call. I'm not sure you'd be able to catch all the runtime potential issues ahead of time (but I've not kept up with php internals for awhile - perhaps someone's got a good way to do that now?)


What I remember from reading master a few months ago:

the zend VM can specialize ops already, trading size of the op-implementations against type-check-elision/fusion by GCC/clang. I think eliding redundant type checks at least won't be hard when confined to a single php function.


Having followed and at times heavily used PHP since the 4.x times, its story seems to be that of slowly (and begrudginly?) accepting modern language features like classes, exceptions, lambdas, GC, static typing, etc., sometimes getting things wrong on the first try but still mostly converging towards modernness.

That begs the question, what's PHP's value proposition for new projects? If PHP mostly chases feature parity with Java/.NET/TypeScript and doesn't attempt to do anything better/different (like Elm/Haskell/Rust/Go/Erlang arguably do), then why choose it?


I am currently working on a web application with two PHP components - one light base application in vanilla PHP, and an administration app driven by the same SQL database using Laravel.

I am having a complete joy building these components, and I find two things to be striking:

My base component does not use a single dependency and it accomplishes a lot! It is really amazing what can be done in PHP with very few lines of code without the help of ANY external libraries, efficiently. I use PDO for connecting to the my SQL database, which is available natively... It can all just be very simple.

On the flip side, my administrative component is driven by Laravel, which yes, took heavy inspiration from Ruby on Rails, but by this point has greatly surpassed it and is very powerful and enjoyable to use.

PHP is the only server side language I would say I have achieved mastery in, so while I am naive to what could be better in X or Y language, I never currently feel held back for what I need to do, and I enjoy doing it.

If you are working in the web niche, what are the reasons not to choose it?


I mean, it's no longer horrible I guess :)

With mainstream languages, there's rarely any single clear and/or insurmountable problem, it's all the little annoyances you run into every day that add up, plus the cognitive load imposed by the language directly as well as indirectly through the code it lets you write.

I'm not 100% up to date on how much PHP has closed the gap in the last few years, but subjectively I never found it anything but tedious due missing features, various unnecessary pitfalls (sometimes with security implications), silly limitations (you can write a static type in this case but not in that, you can catch this error but not that, no inner classes, etc etc.), and numerous other small cases of poor "ergonomics".

The "batteries included" nature of the standard library is nice, and in contrast to the somewhat fragmented world of RubyGems or NPM it can feel downright pleasant, but finding a SQL library or such is a pretty small effort in the scope of a project, and (popular) 3rd party libraries tend in my experience to be better than the equivalent standard library stuff in most of the languages I know. Every time I wrote a non-trivial amount of code with PDO, I had to look up the correct initialization rituals to get sane settings and copy or recreate a bunch of more or less "obvious" helpers. I'm sure there's something better in Composer by now.


There has been substantial gap closing in the past few years and I understand where a lot of the initial hate came from.

This fairly-recent hour long talk covering the 25 year history of PHP by its creator was very good, if you're into that sort of thing =)

https://www.youtube.com/watch?v=wCZ5TJCBWMg

As someone who works in web I have to deal with javascript also, and always enjoyed that too, until node and npm became standard tools. Now everytime I have a project that involves npm I end up wanting to tear my hair out eventually.. I have not had similar issues with Composer.


If you don't have to mess around with PHP extensions, then it all works like magic. Depending on your environment and which extensions you need though, they can be a pain in the ass and then it's more or less the same as managing external libraries.


Thanks, I hadn't thought about that =)


PHP's value proposition has always been one thing - ease of deployment. Seriously, all you need is one install command, one command to start the services, one to git clone the files and one for certbot. And you have a fully functional deployment ready in a single script that can be deployed at scale.

No other language can even come close.


These PHP praises frankly sound like trolling. No other language can even come close? You must be kidding.

I mean I get it. It's obviously a counter-reaction to all the PHP hate that has been with every PHP thread for 2 decades, and much of it has been unfair, especially for the last 5 or so years. But please let's not swing the pendulum all the way to the other side.


So given a web server, what language can 'come close' to the ease of deploying with PHP?


Unless your only experience is 1999 style FTP with shared hosting and you've never used anything else, I don't know how you can claim that `node server.js` or running your Cargo-built server.exe is somehow harder or more complicated.

For example, PHP is complicated enough that people use WAMP/MAMP.exe just for local development.


"Given a web server" seems a pretty big caveat. I'm not a big node cheerleader (even though I work in it day to day), but it doesn't need to be given a web server to achieve the rest of this claim.


I'm a mostly PHP dev, but with apps in other languages, all you need more is a systemd unit file to start the app? (ruby, nodejs, go, etc)


> PHP's value proposition has always been one thing - ease of deployment.

I think that advantage may have been real at one time, when FTP deploys were a thing. The myth loves on. Folks that chant this praise are often not be the same folks that have to maintain the webserver side of things, though.

Easy to deploy looks like this: ./foobar --port=80 > Listening on port 80, ready for traffic

That could be Go, could be Rust. But not PHP.

PHP webserver / application separation does bring some advantages - for example if you bring your application to a corrupted state or crash it, it will go and die. Recovery is, well "implied". But deployment wise, no.

It actually seems to be a LOT harder to run PHP that at first blush. Take this example: https://github.com/laravel/valet/issues/290

Turns out if you php-fpm app one Tuesday at 15:43 starts to write more than 4k to stderr (maybe it writes some nice verbose logs after being hit by some recoverable error), you will find yourself wondering what does "upstream sent too big header while reading response header from upstream" imply while your endpoint responds with 502. This is just one possible footgun .. ekhm .. tuning option.


You would also need a properly configured Apache server wouldn't you? I can see the ease of deployment argument in the context of old-school shared hosting providers, but nowadays how is starting a PHP application any harder than Rails or Django for example.

And for modern development environments, deployment complexity usually comes from managing virtualized hardware and CI/CD pipelines, which is independent of whatever language your app is written in.


In the past I sort-of agreed and even chose PHP in a few instances when the project was tiny enough that ease of deployment was a major factor.

Nowadays with something like Heroku or App Engine, language has almost no impact on ease of deployment, and even custom deployments are pretty easy once you've practiced the docker/systemd script + apache/nginx proxy dance once or twice.


If we're giving PHP credit here, I think we can say with some confidence that the ease of spinning up a shared server with PHP and MySQL inspired the kinds of super simple infrastructure products like Heroku that are now commonplace. The notion that PHP is easier to deploy used to be true, it's not something that should be dismissed, it's even a pretty big deal. It's a walk up experience that inspired an improved DX for every other mainstream environment. But they've caught up and that's worth acknowledging too.


All of that can easily be done in Node by setting up the appropriate scripts in the "scripts" section of the package.json file.


The value proposition is how well the language suits stateless Web Development & HTTP. Every request is an new sandbox, it's easy to pick up for beginners and fast to get started, decent performance, no need to figure out how to compile anything.

From my experience, a huge % of PHP companies started out with a Wordpress site, added a few features then a few years later they are now hooked and are doing things more seriously with Symfony or Laravel.


* Lots of cheap developers available

* Strong community

* Mature frameworks and libraries

* Simple hosting model


Fair, though I'd say 1-3 are more or less matched by Java/.NET and probably NodeJS.

Not sure if you meant this, but now that I think about it, the "one process per request" model is actually legit differentiator that obviates a lot of the concurrency trouble new developers can get themselves into with other languages. It makes good performance harder in some cases (though there are workarounds), but overall it's maybe the one thing in PHP that I'd like to see other languages make some note of.


I'd agree that there are other languages with equally strong communities and mature libraries. I would say it's easier to hire an OK PHP developer for £40K than for any other language, at least that's my experience hiring in London.

The hosting model - what you said, plus not needing to think about memory leaks. There are so many Java and .NET boxes out there that need to be rebooted every 2 hours because of some insidious bug that nobody on the team can solve. It's also pretty easy to put PHP in a container, and scale horizontally.


I can say with confidence if you're hiring a developer for £40K they're not okay. I know PHP communities can be insular and can fail to sell themselves, and I know that local economies can vary wildly, but London is not cheap and 51kUSD is less than half what an "okay" dev should be paid. If you're hiring at those rates you are hiring people who are either unhireable bad at their job or (like I was for the first half of my career) completely unaware of what's available.


Good point about the memory leaks. Not aiming to contradict it, but I'll mention that https://www.eclipse.org/mat/ is a great help in debugging Java memory leaks. .NET probably has something similar.


You don't choose PHP. PHP chooses you.


May be easier to audit a project in a sense due to most common libraries being standard rather than imported.

Has a decent track record for major version updates being easy to migrate to (even if many projects don't bother).

Works for quick and dirty bash-style scripting (not specially better than Phyton, but it does work).


I guess null coalescing assignment operator will save a lot of typing but I'm not sure it leads toward a more readable code, especially with ?? and ?: already part of the language.


I suppose alternatives like ||= or //= have their own issues.


> It is now possible to escape question marks in SQL queries to avoid them being interpreted as parameter placeholders. Writing ?? allows sending a single question mark to the database and e.g. use the PostgreSQL JSON key exists (?) operator.

Good.


Why this, can someone please explain.

Numeric literals can contain underscores between digits.

<?php 6.674_083e-11; // float 299_792_458; // decimal 0xCAFE_F00D; // hexadecimal 0b0101_1111; // binary ?>


Here's the RFC for it with the "why" and discussion of the tradeoffs. https://wiki.php.net/rfc/numeric_literal_separator


Underscores in numeric literals are also now pretty much a defacto standard. Java, JavaScript, Perl, Python, C#, Ruby, Rust, Swift, etc, all support it.


Thanks for the link.


Why is this garbage fire of a language still alive is one of the big mysteries of the universe


Another step in the homogeneousness of ~dynamic programming languages. PHP is now near ES6 parity, which was a ml/scheme revival.


Arrow function and spread operator, that's so... ES6 :o


Syntax wise I suppose. Though other languages had similar functionality long before ES6.


Says a lot about the overdue features of PHP


There's a lot of PHP positivity in the comments. I just want to inject some sobering pessimism in here, as someone who has spent the last 6 months using PHP for the $dayjob, and used to do commercial PHP work back in the PHP5 days.

PHP ....

... Doesn't ship with a production ready webserver. Yes, Python and Ruby also don't, but they have easy tools you can reach for (gunicorn, Puma) if you need to run them in a modern deployment stack where a whole nginx isn't really necessary.

... Doesn't have basic collection types in the core language. It's 2019 and PHP still thinks it's logical for the standard language to throw all Map, Set, List semantics into a single PHP array type. You can install the "phpds" native extension (and polyfill it from Composer) to get some passably usable implementations. But coming from Golang / Rust (or hell, even ES2015) I find them frustratingly limited.

... Doesn't have any sort of threading / async support. Even in a modest-scale webapp, this is going to hurt you when you want to do things like deploy PHP as a job queue handler. Or fan out even a trivial number of HTTP-client API calls from a PHP controller in a microservice-y world. The latter can be sort-of achieved with naive hacks like the cURL client concurrency support (Symfony HTTP-client supports it: https://symfony.com/doc/current/components/http_client.html#...) but that's a hack at best.

... Doesn't ship with a debugger out of the box. Even with great tooling like phpstorm IDE, you have to actually rub braincells together to be able to get xdebug installed / configured and ready to use.

... Has a somewhat decent package manager (Composer). But it doesn't ship with the language. Also, it's kinda crappy. It's painfully slow to do a composer install/update on anything larger than a toy project. It has all sorts of weird non-determinism issues (the composer.lock file flails around wildly between runs, changing case of metadata fields, etc).

... Has semi-decent static analysis tools (Psalm, phpstan), but they're pretty garbage compared to a proper compiler, or the quality of static analysis tools in other dynamic languages like Ruby / Javascript.

I could keep going. Profiling, code formatter, library ecosystem quality, and so on.

Where am I going with this? Honestly, I wish PHP would just die. It has some pros, but overall it's a terrible language that has no hope of modernizing enough to be relevant in 2019 and beyond. There's plenty of other excellent languages that do a better job in any category that PHP attempts to be good at. The effort being spent to maintain PHP as a language/runtime could be better spent on other languages that have made better choices in language design.

The developers who have become proficient in PHP, should continue to use their employable skills to maintain existing PHP codebases, but take a bit of time on the side to get proficient with another popular language if not already. And for the love of god, stop starting greenfields projects in PHP! Let it fade away peacefully.


I wonder why they added the "fn()" thing on the left of the array functions.

    Javascript: $square = $x => $x*$x;
    PHP       : $square = fn($x) => $x*$x;
Probably so that it works inside arrays:

    $a=[fn($x)=>$x*2,fn($x)=>$x*$x];
    echo $a[1](5); // 25
Well, it also makes it a tad more readable, so I am ok with it.

Since we are talking about new features of PHP: Does anybody else wish there were named parameters?

I think PHP is pretty complete. It is my favorite language and I don't really wish for anything added to it. Except for two things:

1: The named parameters of Python:

    def paint(what,color='blue',tool='pen',layers=1)
        ...
    
    paint('house',tool='brush')
2: The short object Syntax of Javascript:

    city={name: 'Berlin', population: 3748000}


As you mentioned the => syntax is already being used in PHP with associative arrays and can conflict in some places. Taking your example [$x => $x*2] this creates an array with $x doubled on index $x, while a user might want to create an array of functions.

The fn() syntax was a non-conflicting alternative, which got most support for being not too weird.


I wonder why they didn't use `==>`, which PHP alternatives like Hack[1] already use.

[1] https://docs.hhvm.com/hack/functions/anonymous-functions


In the end it's a matter of taste and preference. There are other options as well. Each contributor (and user) certainly has a favorite and in the end it is the solutions with biggest support (and least objection)

Bike shedding can certainly be done infinitely and sometimes one has to make a choice and move on.

(I have been release manager of PHP in earlier times and helped to steer through the namespace seperator debate and did the decision to not do short array syntax, yet, but wasn't involved in the short function syntax debate)


Mixing named parameters with unnamed ones is ripe for confusion. The syntax is also going to get rather ugly now that parameters can be typed, too. If I need to pass around more than 3-4 parameters and their names/types matter a lot, I think I'll just define a class with clearly named properties and pass around an instance of it.

I'd love to have a shorter object syntax, too. For the time being, I'll make do with

    $city = (object)['name' => 'Berlin', 'population' => 3748000];
which is a little verbose but gets the job done.


I think there is an rfc for object initialization similar to C#:

    $city = new City {name: 'Berlin, population: 374800};
Edit: found it (and it uses = instead of :) https://wiki.php.net/rfc/object-initializer


TypeScript spoiled me. I want PHP to have generics and all the type-system goodness that TS brings.


That would be great. I would also love it if TS supported runtime checks like PHP.


My thesis was working on top of ConcreteTypeScript, which supports runtime checks https://github.com/ludamad/LocusTypeScript. My contribution was adding the ability to define types inline with code, and check those using tagging. That being said, it's all very experimental.


I’ve wanted named parameters for years! There was an attempt about 6 years ago but it went nowhere.

https://www.reddit.com/r/PHP/comments/50xcmi/what_happened_t...


Because there are several contexts where $x => $x is already valid PHP to mean something entirely different (array, foreach, ...).


would like if they'd just change the syntax to foreach(something as k,v) or $arr = ['something':'value']... or then could use => ...or they could just use -> and change -> to . notation.. I use js a lot more lately so having it closer resemble es6 would make jumping back and forth easier.. I often start writing a json object when I want an associative array.


... change three different operators because you can’t handle the syntax of two different languages? Sure why not.

Perhaps php should also drop all type information so it can be more like the cluster fuck that is “modern” JavaScript too? Maybe change “const” so the constants it declares aren’t... constant?


> I wonder why they added the "fn()" thing on the left of the array functions.

There would be ambiguity without it: https://wiki.php.net/rfc/arrow_functions_v2#syntax


But does it have to be =>? How about ~>?

    $a=[$x ~> $x*2, $x ~> $x*$x];
    $a[1](5); // 25
Looks cool to me.


~ is annoying to type on some keyboard layouts (Alt Gr and + onna German keyboard)

Also PHP tries to be "googlable". Typing "fn PHP" into Google should bring relevant hits, for people never seen such a construct.


> Also PHP tries to be "googlable".

If not insisting on the "google" part, there always is http://symbolhound.com/?q=php+%7E%3E


I noticed lately google is starting to understand symbols in certain contexts. Searching "php =>" actually does provide relevant results.


There's some rationale here[0]. Basically they'd need to use a parser that on ambiguities would have to go down all possible routes concurrently until all but one fail, which can lead to performance costs. Using a prefix keeps things simple.

[0] https://wiki.php.net/rfc/arrow_functions_v2#x_x_y1


To prevent ambiguity at parser level. To prevent collision with array definition.


For those who want to use on serverless functions the new PHP functionalities there is a way using Cloud Run.


Did you really copypaste a tweet in here ? What kind of new kind of spam is this?


I copied a tweet because I was lazy to write another text. Honestly.


Fair enough.


I have been waiting for a strongly typed mainstream high level language for a long time (TypeScript doesn't count because all type information is stripped during runtime). PHP still has a lot of cruft that prevents me from using it in my projects, but the recent updates seem like a step in the right direction. Hope that by PHP 8 the language will have deprecated more of the bad stuff.


> TypeScript doesn't count because all type information is stripped during runtime

What's the point of keeping this information around at runtime if you do all your type checks at compile time?

Based on this categorisation, Haskell for example isn't a strongly typed language, and yet Haskell's type checking is one of its biggest selling points, so this doesn't seem quite right.


> What's the point of keeping this information around at runtime if you do all your type checks at compile time?

It forces you to write input validation code that stays in sync with your types. Otherwise bad input can invalidate all your type guarantees.


In practice, you don’t do all your type juggling at compile-time in even moderately complex libraries or applications. So TypeScript could certainly use better RTTI, I think. design:type metadata is insufficient.


Reflection is really useful. Right now the only way to differentiate types at runtime is testing for the existence of a key, which is kinda hacky.


You really don’t get most of the benefits “Strongly typed” languages here. A program that fails with type errors at runtime instead of compile time is the worst of all worlds.


Continuing to run with unexpected type coercion bugs could be worse than bailing out. So, worse than compile time checking, yes. But not the worst.


It just seems to imply that you need input validation code regardless of how your language is typed.


> A program that fails with type errors at runtime instead of compile time is the worst of all worlds

Better than silently failing! + if code fails early as these type checks can enable, then bugs are often (not always) picked up just by running the code once.


You can use third-party tools to check ahead of time, and you can fall back on the PHP runtime to catch what can't be caught in advance.


This will help you find type errors if you have good test coverage without explicitly testing for types. Makes tests shorter.


Typescript counts. Write well typed runtime code, get type safety and runtime safety. See io-ts as an example: https://github.com/gcanti/io-ts


why not Go/Java/....? Honest question.


At least for Java, PHP has the massive advantage of "change the code, save it and hit cmd+r" while Java, JavaScript and .net require recompiling, repackaging and deployment.

At work I develop for both PHP and Java projects and... it's cumbersome to develop for Java projects, to say it nicely. Ever tried developing for Jira, Jenkins or enterprise CMSes?


> while Java, JavaScript and .net require recompiling, repackaging and deployment.

Not to be a pedantic curmudgeon... actually, precisely to be a pedantic curmudegon... javascript does not require any of that.

The byzantine and asinine ecosystem that has sprouted like a cancer around javascript when SV and Node noticed the language and its profit potential, fueled by hype and unnecessary complexity? Yes. But the ecosystem is not the language.

Javascript itself is exactly like PHP in this regard - you edit a file, upload to the server, refresh the browser.

Everything else is unnecessary. Useful? Maybe. Bullshit? Probably. But not necessary.


I was recently surprised with this. I liked ThoughtWorks' tech radar. It's all client side JS, but uses node for some reason. Took longer than I expected to figure out the ecosystem (hadn't used node before), and it didn't appear to add much value for this use case. It also downloaded a boatload of node modules, and something called Cypress that takes forever to run. In the end it produces a fairly pedestrian client only SPA.


It's like the tale of the boiling frog. I don't like how with old school Javascript you have to add script tags to your html for each library you want to use, at some point you start using a bundler, then a package manager so you don't need to download them manually, then a compiler so you can use newer Javascript syntax, and so on and so on. Each step is better than the last one, but when you look back to the start things do seem simpler back then.


Since when does native/plain nodejs reload the source file(s) it’s running when they’re changed on disk?


I'm not talking about the limitations of Node.js, I'm talking about javascript as it's deployed to the web, from a server, running in the browser.

That use case, the one for which the language was intended, does indeed work as described, and has for decades.


Right, I didn’t get that at all from your original post.


sure, there are pros/cons in all languages. My question was specificly to the sentence about "strongly typed mainstream high level language" - as there are many languages who fit that definition.


Maybe they prefer optional OO over mandatory or no OO?


maybe? I wouldn't know.

"strongly typed mainstream high level language" does not say anything about that, hence my question.


C#?


C# + .NET Core 3.x + Blazor server-side. This is modern PHP.

I've gone all-in on the Microsoft stack and have not regretted a single moment of this decision. If one can put aside the "big evil company ecosystem bad" argument for just a moment, I think it would be very difficult to say another ecosystem is superior in terms of actual time-to-market for your product.


I tried C# + .NET Core recently, and while the core language was excellent, I found the library ecosystem severely lacking compared to the PHP and JavaScript ecosystems.

And some of the best libraries which did exist were under commercial licenses! Which generally isn't an issue in other ecosystems.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: