Hacker News new | past | comments | ask | show | jobs | submit login
New in PHP 8 (stitcher.io)
326 points by jonifico on Feb 3, 2020 | hide | past | favorite | 255 comments



At these rate of improvement, along with Laravel, may be I should seriously evaluate moving back to PHP stack. It was only the other day Antirez, author of Redis [1] was complaining the Ruby Stack is more complicated than it should be. And I wholeheartedly agree.

[1] https://mobile.twitter.com/antirez/status/122328600521977446...


There was never anything wrong with PHP, really.

* If you wanted to scale it horizontally, it was ready to do that 15+ years ago

* No problem running it completely stateless

* Deploys are completely sane and predictable, it's just a bunch of files, and even when composer came along it didn't really change that too much

* Performant enough as far as the interpreted web languages go

* No problem writing a RESTful backend in it and fronting completely "modern" client facing tech on the top if you want

* Server side rendering since day 1

Like, it came down to people complaining about some function names / param orders as if it were the end of the world. I think a certain subset of people (shall we call them hipsters?) are just keen on finding new ground where they can rewrite the same boring things instead of working hard to improve the ecosystem of something existing.

I moved on from PHP aeons ago because it got this undeserved bad rap, but I still follow it and would welcome the chance to run it again.


It's fine to like PHP and I'm willing to believe that modern PHP is a lot better than what it used to be but it annoys me that every time the language is brought up these days some people feel like rewriting history to pretend that PHP-bashing 15years ago was just a baseless memes made by haters who didn't get it.

There was plenty of wrong with PHP. There were very unsafe defaults, poor API choices, poor coding standards, inconsistent syntax, paper-thin C bindings that didn't provide the level of abstraction you'd expect from a scripting language etc... If you've forgotten what PHP used to be you can just take a trip down memory lane by browsing through this classic: https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ . Lest we forget PHP was started as a templating engine that evolved haphazardly into a full fledged programming language, and it showed.

If you think PHP is a good language today then say that, but let's not pretend that the complaints and ridicule were always undeserved.


> If you think PHP is a good language today then say that, but let's not pretend that the complaints and ridicule were always undeserved.

It's a question of when do you let that go?


Right, I don't think it's necessarily the people that are _for_ PHP are ignoring the past, it's that the people _against_ PHP are still stuck in it.


This is a common straw man; PHP 5 and 7 made large strides, but that's because there was so much to fix, and there still is and will continue to be, like lack of first class functions, actual modules, etc. PHP is also unsuitable for persistent processes like serving WebSocket.


Why do you need "actual modules"? I feel that (when PSR-4 is followed) PHP's code separation practices are among the best, especially compared to other interpreted web-languages (Python, Ruby, js). And it's convenient while experimenting that it doesn't really enforce anything.


Without modules there can be dependency hell: conflicting subdependency versions, unless all your dependencies update their subdependencies in lockstep.


Websockets are no problem with Ratchet. OhDear is a high traffic app that uses laravel-websocket (based on Ratchet) with absolutely no performance issues.


Ratchet works fine.


They probably still have to maintain systems running PHP 5, and are quite literally stuck in it ;-)


Never, since PHP is fundamentally flawed, and trying to redesign it would make the split between Python 2 and 3 pale in comparison. PHP's main selling point is backwards compatibility and the existing ecosystem; a fundamental redesign would remove that. PHP's name is also mud when it comes to programming language design, and its community is notorious for poor practices, so no one's really clamoring for a more modern PHP.

The bitter truth for PHP stans is that it is what it is, you can get things done, and you can have valid reasons for using it (like legacy reasons, job market, etc.), but it's rightfully trending down and will continue to.


Oh, PHP definitely sucked before 5.


> Deploys are completely sane and predictable, it's just a bunch of files

This was absolutely the killer app for PHP. It was lucky enough to be well integrated with Apache, and crucially could run as a non-persistent per-user interpreter behind the web server. This made it exactly ideal for deployment in shared hosting environments. The fact that you can't do this with e.g. Node forces all sorts of containerisation yak-shaving on us.

People tried to do this with a few other languages, such as Apache mod_perl, but PHP was the one that thousands of cheap shared hosting providers made available, letting people get started with web development.


I started my career as a php dev 15 years ago, and yes, there was plenty of wrong with php. Messy Api, terrible default, wonky typing, no namespace, etc.

It succeeded, as it's often the case in IT, not because it was the best, or even very good, but because it was easy to adopt and had a killer feature.


> there was plenty of wrong with php. Messy Api, terrible default, wonky typing, no namespace, etc.

"Messy Api" is discussed above ("it came down to people complaining about some function names / param orders as if it were the end of the world") so I won't comment.

"terrible default": would be interested in specifics here

"wonky typing": every scripting language had wonky typing 15 years ago, and many of them still do today. This has never been a valid criticism of PHP when comparing to it's primary competitors.

"no namespace": THIS is a very valid criticism. PHP really wasn't a sane language before they added namespaces. But... they added namespaces 11 years ago.


"Messy Api" isn't just parameters. For instance "Fatal" errors and regular errors going to two different logs was very messy and would byte you if you didn't pay special attention to it.

Or multi-byte compliant methods that are a variants, and not the standard method, thus biting anyone who just thought utf-8 would be default.

"terrible default": the poster child for this is register globals, which it took ages to have off by defaults. That's just a single line to set it properly, but that was part of the boilerplate that could have been avoided way earlier.

Overall developing for PHP meant to defensively remember a ton a weird stuff, just like javascript was for a while. I am so glad we mostly got past that, even if I am not in PHP anymore.


Fatal errors is fair enough; though I only ever experienced this with parse errors, PHP being stateless did make this less likely to be caught until well into runtime, so it could be an issue.

String encoding though is, again, something other languages had similar gotchas with. Remember we're comparing PHP to its popular alternatives at the time, not to our hypthetical ideal runtime.

The bad defaults you and a sibling commenter are referring to (magic quotes) are, again, from 11 years ago.

Sure, 15 years ago PHP had serious issues, but here we are today acting as if they didn't fix most of them over a decade ago.


> but here we are today acting as if they didn't fix most of them over a decade ago.

Recall that the defense of PHP in this tree leads with "There was never anything wrong with PHP, really."


> The bad defaults you and a sibling commenter are referring to (magic quotes) are, again, from 11 years ago.

That's because the context was the state of PHP 15 years ago.


> would be interested in specifics here

Magic quotes would be the first one I can think of off the top of my head, which incidentally, was made a default because the mysql api in PHP was so prone to sql injections, that PHP decided to automatically escape all user input as a way to protect inexperienced programmers.

Pretty much everyone agrees magic quotes were a bad idea and they were eventually deprecated in 5.3 and removed entirely in 5.4.


Php has had some really poor errorhandling and lots of magic. The idea that good error handing is just ignoring it is so wrong, that every update to php is basically a list of “this error will now be presented to you”.

How many scripts continue to prohibit apostrophes in passwords because there used no way to reliably instruct devs on how to handle apostrophes in strings? People named O'Brien still can't enter their names in forms and expect to get it back despite magic quotes being gone years ago.

Nowadays, modern php is conservative but fine. But it was really a terrible choice in its early days, when every one of its selling points was a misfeature.


> How many scripts continue to prohibit apostrophes in passwords because there used no way to reliably instruct devs on how to handle apostrophes in strings?

Thankfully this problem was solved back in 2004/2005, but unfortunately shitty code was already pervasive and the “right way” wasn’t heavily communicated enough.


I have a framework that has a database backend that relied on some default behaviour of count() where if you don't put in an array, it would just return 0 and not error.

Broke in 7.x because it would now warn now... I don't remember what it returns now but that was a thing...


PHP was the MySQL of programming languages and there was plenty wrong with it, mainly the dumb defaults that cause incessant security issues, all the inconsistencies and the habit of papering warnings over errors.

This release is another step in resolving these problems.


> the dumb defaults that cause incessant security issues

The first Java web shop I worked for had a homegrown version of magic_quotes_gpc. That’s when I realized that those who had gone through making PHP installs and apps secure had very valuable experience.


Interesting point! I learned a lot about security due to php. The problem was always that you don't know what you don't know. I recall going back to my first php site from like the php 3 days and I had zero SQL injection protection – I just didn't know it was a thing.


I think that is unfair to MySQL. MySQL is and always has been a fantastic piece of code and to my surprise it has developed and improved under Oracle's stewardship.


PHP has always been a great piece of code as well, there clearly is a reason it is used so much. Like PHP, MySQL used to have stupid defaults though, like silently ignoring errors.


Function names and parameter order matter. That is the difference between having to look something up in the documentation and not. Back in those days most text editors didn't have fancy autocompletion with parameter documentation, if you weren't sure about the order you might have to look it up in the documentation. Having a self-consistent API that was easy to remember was essential. Especially in a language with dynamic types!

When I switched from PHP to Python it was an amazing, liberating feeling for me that I will never forget.


It takes 10 sec to google "str_replace" and have the params presented to you. Using a manual is an integral part of development. I don't think there's many people who can memorize all the methods and their params, including optional ones, nor should they.


Strongly typed languages have better autocomplete since ages, so in Java you would simply type "Str" in Netbeans and you would get all of the ways to create a String or StringBuilder including the parameters right at your fingertip without context switch. No memorizing except the vague notion of "sometimes you want to use a StringBuilder instead of String". Just keep typing code.


You mean statically, not strongly typed. Strong typing roughly means avoiding implicit type coercion.


10 sec every single damn time, for like 4 years, until i switched to other language (ruby). And like google once or twice to remember params in %sanelanguage%


That sounds like it takes a lot more time and mental energy than if the API were consistent.


We have machines to do that for us. As in, "press Ctrl+Q, IDE shows relevant help." I don't value encyclopedic knowledge of every API out there any more...especially since those I do recall are of rather, um, limited use nowadays. Like with any language, the point isn't to cram a dictionary into your brain, it's to communicate.


It's a red flag if the basic operations (like string and array functions) are so inconsistent and weird so as to require use of an IDE or constant use of the docs.


Back in the day everyone has the PHP manual downloaded in CHM format (that was before broadband was common). Searching in CHM was just 1.5 seconds away.


Python???! Python2 vs python3 is probably the worst thing I have ever seen a language do. Now teams are stuck supporting both versions, new devs are always confused, teams can't upgrade, or if they do upgrade much of their python2 code is useless. The language is now filled with hacky crap: urllib, urllib2, urllib3 and ... AND python is slow.

"That is the difference between having to look something up" PHP (for 15 years?) has had IDEs that fill it in for you.


I am honestly confused how anyone could code themselve up into that python2 only corner. With the release of python2.6 and python3 in 2006, it was clearly described what one had to do to write upwards-compatible python2 code. 2006.

https://www.python.org/dev/peps/pep-3000/

No one had to have any problems with the transition. If they did, they had to willingly ignore the in-your-face documentation on the migration process.


But they did, and they will always do at every turn...

I am not against making something not backwards-compatible. I am in favor of throwing old, bad things away even at the risk of having to rework some stuff... But how crazy legacy is at every damn company is just making it so frustrating. They will happily just wait it out for 14 years and then complain about their Python2 being desupported


I kept the php docs open all the time. Alt can over, type the function name. But, honestly, you just start to remember all the different little gotchas (at least back in the v3 days).


> There was never anything wrong with PHP, really.

Looking at the Python standard libs vs the PHP standard libs, PHP used to be a bad mess. Other than that, it's still brilliant.


the biggest point is that people are focussing too much on PHP own quirky edges but then are fine with other languages insanity (I'm looking at you javascript and python). PHP is not perfect and I'm pretty sure it's bad name comes from code written for wordpress or joomla or the guy that came before you than PHP itself. Otherwise I can't understand how Python or Javascript can get away with way worse issues.


what python issues do you have in mind? the linguistic gotchas i can name off the top of my head are:

- the way mutable default arguments are handled

- the weird behavior of closures referencing loop variables

- leaking variables out of if/for/with (yes, i know it's convenient, but can bite sometimes)

- GIL stuff

- exec not being able to introduce new local variables (yes, i know code-objects have their local variables decided at compile time, but it's surprising if you don't care about that implementation detail)

other than that i can't think of many "insane" behaviors that can bite you. i'm curious what you're referring to!

and sure, i'd change a lot of the language to make it more FP-friendly if i could, but being what it is, the semantics seem pretty unsurprising most of the time


Isn't the base indentation style of Python insane ? I remove a "if:" block and and have to press backspace, maybe 100 times ? If I add one "if:" then have to press 100 times on space ?

Yes, nice you can have Python-adapted editors where ident levels can be tuned, but no, it's still a big defect


No, the indentation is a feature.

Your editor can help you with the editing. (And the problem you mention are exactly the same, if you write production code in other language. Your teammates will hopefully insist on consistent indentation in C or Java as well.)


it's never really been a problem for me, i just select the block and tab or shift+tab it as needed. honestly i'd be doing the same in C or whatever braces-based language


> No problem running it completely stateless

It's a problem for some use cases, and even in the web use case, reusing connections to databases and services can be a pain with PHP because it's completely stateless.


Persistent connections are available and if your connection dies the db request will continue next time the page is hit. Although that could cause more slowness issues.


> reusing connections to databases

pgBouncer and ProxySQL are going to give you a better bang for the buck than a stateful web app will.


Maybe. Kinda. Not really.

You can have an awful implementation of a connection pooler, sure, but opening an authenticated socket is more expensive by far than just referencing one.

Less so for a unix socket/named pipe- but still much slower than a memory lookup.

Of course you probably don’t care until you hit a certain scale or number of backend system accesses.


Fetching a connection from a (sane) pool isn't just a memory lookup. Database conenctions have to be cleared of state (transactions, temp tables, prepared statement handles, ...) which takes time as well. Otherwise one runs into "funny" bugs at some point in time.


Unless they're local (and managing that fleet would get pretty annoying), there's still unnecessarily TCP overhead, and even the possibility of exhausting ports.

I'm not arguing for a truly stateful webapp, but the connecting pooling you get for free (or some library wrangling) with a long-lived process does a lot for performance and scalability.


Compare https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ which is not really about the strawmen you mention.


2012. I did agree with it wholeheartedly, when it came out and PHP 5.3 was brand new. It is now 8 years and several major versions later, most of the critique is obsolete and the rest is just "let me try to write horrible code; see, PHP is horrible because it's written in PHP!"


The comment I replied to said: 'There was _never_ anything wrong with PHP, really.' (Emphasis mine.)

Btw, I do agree with most of the changes Facebook's Hack made to PHP.


Oh, ok. There was an immense number of things wrong with PHP. It's gotten to the usual manageable level of $anylanguage.


> Like, it came down to people complaining about some function names / param orders as if it were the end of the world.

Arrays go (needle, haystack). Strings go (haystack, needle). There might be a couple of exceptions but that's basically it.


Higher order functions are inconsistent as well. There are many more examples. The language feels (is?) patched together.


I've been working on a dead simple service to deploy and host Laravel/PHP applications without having to do system administration. https://www.amezmo.com


It was more about certain communities highly valuing "prettiness", such as RoR.


At the time of Ruby (driven by Rails) starting to draw people away from PHP I think there was much more value attached to a single "right way to do it" than just Ruby being prettier. In the current world with Laravel and other frameworks in the PHP world its less of a thing, but at the time every PHP application I worked on came with its own half-baked framework coupled together from various libraries, and missing some feature or another. Moving to Rails where you could jump into any application and at the very least understand the fundamentals of where particular bits of code belonged from the offset was a breath of fresh air.


Hell, I maintain an application where the person who originally programmed it reimplented Rails in PHP (except worse)... It gives me all kinds of grief lol


To be fair, there is something to be said about the aesthetics of a language, and Ruby is (at least to me) a far more readable and "pretty" language than PHP. There are a lot of small niceties that, once you are familiar with them, make Ruby genuinely enjoyable to read.


> and Ruby is (at least to me) a far more readable

It’s funny folks pick on the “Magic” in PHP, yet overlook all of it in Ruby. I’m not a PHP guy anymore really (now Python/Rust/Java/Ruby mainly), but I’m still continually annoyed reading Ruby code. Here’s an example:

- find a method being called on a class, so want to find out details on said method

- grep through codebase, find no definition for said method

- grep through all gem dependencies, find no definition for said method

- search web, don’t find any obvious leads

- cry in despair

- finally find that method is handled by a method_missing on a dynamically generated class and never has anything related to the method name even as a string

- flip desk and go home for the day


Meta programming became far less common in Ruby, I barely see it in Rails apps anymore.


Yes, once you are familiar with. Otherwise, PHP with its generic curly-brace syntax is way easier to grok (I have to work on a codebase in Ruby and the funny syntax + no strongly typed compilation pass makes it really hard for me to get started modifying things).


This. And I do agree with all the point parent mentioned about PHP, it is just now I am a lot older I am starting to question this higher value of "prettiness".


>> There was never anything wrong with PHP, really.

I mean, your listed points are arguably correct, but this sentence is quite incorrect.

edit: downvoted by PHP fans. It's OK, I get it, nobody likes it when others dunk on their favorite language. :)


You were downvoted because your post lacked any real content or rebuttal (and, probably, for the edit - no one likes it when people complain about downvotes).

FWIW though, you're absolutely right - there was (maybe still is?) an enormous amount wrong with PHP. The only real rebuttal core-questions needs is a link to the classic essay, "PHP: a fractal of bad design" [1], which lists far, far more problems than just issues with function names or parameter order, and does it more comprehensively and with more style than you or I could hope to.

[1] https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/


One I always like is people using "mysql_real_escape_string". Well guess what? It comes from mysql itself: https://dev.mysql.com/doc/refman/8.0/en/mysql-real-escape-st...


Lots of "classic" PHP is just thin wrappers of C libraries. Many of the inconsistencies in PHP come from being consistent with those libraries.


Not really. You may be surprised to learn, as I was, that PHP function hashing mechanism was strlen() in the beginning. So the number of characters was more important than naming consistency.

https://news-web.php.net/php.internals/70691


Yes, I was shocked to learn this about early PHP, that function names were hashed simply by their lengths - so names were chosen to fit a specific length. Pragmatic and fast? Yes. Insane design? Completely.

Edit: I can also imagine this design decision must have had context. Perhaps it was a common technique in low-level programming, as a practical way to save time/space.


Given the amount of functions in early PHP (we are talking PHP/FI 2 max here, even userlevel code hardly had functions back then) even not hashing them at all, but doing a linear search over the function table would have been acceptable. Hashing by length most likely lead to few buckets with more than 3 functions.


That is for function with no C counterparts. htmlspecialchars() exists in no common C library. The reason strlen() is called strlen() (not string_length() or length() or whatever) however is due to C.


A "classic" is timeless (cf. Reflections on trusting trust, published in 1984). This essay used to be spot on; with age, it didn't become classic, it went the other route and became obsolete (as it was rightfully critiquing PHP 5.3).


If this is a way of advancing the case that PHP is no longer bad, well, sure. I allowed for that, it may be true, I can’t say. We were discussing whether it was ever bad, which it clearly was. But sure.

On the other hand, if you’re trying to nerd-snipe me into a debate over the meaning of the word “classic”... :)

I’ve gotta disagree with your characterization. At least in the field of jeremiads, surely the criteria can’t solely be timelessness - that’d imply that an essay that successfully inspires change couldn’t be a classic (not that that’s what happened here, I’m not directly attributing anything to anyone). Words are hard to pin down, but I think when it comes to screeds, what’s “classic” could be, in fact, whether it provoked some kind of change - if at the time it won hearts and minds. Or, what’s “classic” could be not necessarily about the specific thing it’s arguing against, but instead about the underlying principles guiding that argument. Or maybe it’s about the style, panache, humour, or clarity with which those principles are argued. Maybe some combination of all of the above.

No one programs with gotos much anymore, but “Go To Statement Considered Harmful” is probably safe to call a classic. America is an independent nation and King George no longer holds the British throne, but nevertheless the Declaration of Independence is certainly a classic text. For reasons of style, persuasiveness, its underlying principles (I think anyone designing a PL should have read it), and its widespread popularity and influence at the time it was written, I think the PHP essay counts as a classic too. YMMV.


Dunk? What you've done is stood on the other end of the court, holding the ball and said "I can dunk this ball" then left the court.

If you've got some counterpoints or arguments, please give them. Going "lol php bad" is just dumb.


I would say that e.g. the current Rails stack actually is quite complicated, but that's because the current web stack is a horrible mess and Rails does the brave attempt of managing all, from providing images to delivering JS packages to friggin' websockets.

This isn't contrasting Ruby to PHP, this is contrasting the web that was with the web that is.

And actually, even when Rails was founded the PHP stack was inadequate for this -- which is why current practice includes all the parts that antirez is complaining about? Gems? PHP has composer, barely any serious project doesn't use it. Rack? Granted, once the PHP server is setup you don't have to account for an abstraction layer. Rakefiles? I don't think there's a standard task runner for PHP, but e.g. Laravel has envoy and I would assume that almost any project needs some kind of shim there, even if it's just shell scripts. YAML? Well, erm, ok, I won't defend that…

The times where PHP means directly accessing a `.php` file for every "page" have passed by. If you look for simplicity there, oh traveler, beware…


This is the app antirez was complaining about: https://github.com/antirez/try.redis

It's not even a Rails app. No idea what he was complaining about exactly, but certainly not Rails.


RoR shares the features he was complaining about and then adds some more. As do most other frameworks concerning the same type of web apps, including those written in PHP. And sadly most of it necessary, if you don't just serve templated HTML or provide an API. Once JS gets into play and you have to invite friendly Mr. Webpack, the blood-dimmed tide is loosed.

Looking at the original app, the Rakefile for example seems mostly to be there to start Redis? How would we have done this in the olden days of the *AMP stack, assuming the task has to run on both Windows dev machines and the Linux server? Heck, we might not have been able to do this at all, if we just had file and not shell access...


That's pretty much where I was getting at. The stack he complains about is very barebone, and I doubt he'd have anything simpler with PHP or any other stack.

> rake

As you say it's a simple task runner like make. Maybe use a shell script instead, but appart from that, hard to be any simpler.

> rack

That's just an interface, the equivalent would be mod_php & co, not any simpler in my book.

> gem

Not sure what's there is to complain about here. It's a fairly straightforward package manager. Unless you stick to the stdlib, I doubt PHP packages are any easier.

> yaml

Many people hate it, but for simple configuration it's not any worse than JSON or XML. Matter of taste I guess.

I'd be happy to hear or more detailed complaint from antirez, but I don't think anything can be inferred from that single tweet. This reads like someone who hasn't worked with Ruby in a while, and is grumpy he has to figure a few things out again.


It's true, the requirements for web apps became bigger. If you compare Rails to Spring it's actually very simple. It's comparable in time to learn to Django/Laravel


> This isn't contrasting Ruby to PHP, this is contrasting the web that was with the web that is.

Wait, are we really calling Ruby/Rails the "is" of web development in 2020?


I'm calling the current version of RoR able to provide what the "is" state needs, while staying within the Ruby world (like antirez' example did). My point was that basically any other stack would be at least as complex when it comes to the infrastructure than this, most likely even PHP.


Huh, I really don't see that. Modern web development usually means some Vue/react/angular frontend decoupled from a backend that could be running literally anything. I'd give php some performance props over other scripting languages but obviously there's go/Ruby/python/whatever in the mix and they all work admirably enough and are usually reverse proxies.


I don't know what you call 2020 web development but in last 2 years i'v been able to co-develop several web apps in Node.js and also complete "serverless" ones using only AWS services and oh boy.. Rails is still so far ahead


Rails is effective and nice to work with, PHP isn't half bad. I think these languages got a bad rep by frustrated Cobol developers or something...


Symfony (https://symfony.com/) and Slim (http://www.slimframework.com/) are also worth looking at. Though since Symfony has become more modularized, I think it can also be used as a micro framework.

I've also started looking at Flask and Django of Python, can't help the feeling, that the Python frameworks are a bit more mature in terms of breaking changes.


The Laravel ecosystem (framework + libraries) is a very productive and developer-friendly stack. Documentation and training resources are ample and the community is generally very open and patient to both new and experienced developers. If you're already comfortable with PHP or just want to try something new, definitely consider Laravel/PHP as an option. You might still opt for Node, Ruby, etc., but I wouldn't simply disregard Laravel/PHP for historical reasons.


I've recently moved back to PHP; stuck on a php 5 version, but I was surprised at how fast I was back into it.

It has a heap of problems due to mistakes made in the past and - perhaps more worrying - a LOT of misinformation posted on the internet. Then there's the trope of PHP developers always building their own frameworks and CMSes and the like.

And I'm dealing with a big legacy codebase where the original author did not understand separation of concerns (or sql injection for that matter), with constructs like a switch returning a different SQL query depending on a string value, globals to store the result in (which is concatenated XML transformed to JSON at the bottom of the 5000 line file, which in turn includes thousands of lines of additional code). And the project was started in 2012, when modern PHP and frameworks were already a thing.

I'm doing new work in more neatly organized classes at least.


This is pretty awesome, I've been migrating from C# and NodeJS back to PHP and it's awesome. Want to know why?

- Everything is either built-in or can be enabled from an OFFICIAL repository (like functions for bc,xml,etc). No more trusting sketchy npm packages or having to pull in a ton of dependencies that might stop working some day.

- It's so fast and elegant to consume a (SOAP or REST) webservice. Visual Studio insists on creating tons of files, obscure web.config settings and other misc. stuff. PHP handles this in a couple of lines.

- Development feels natural, every file can be a single class if you want and there are plenty of highly matured frameworks available.

I estimate I've slashed development time in half compared to C#, less bugs and less security issues (verified through two independent code auditors). Even large projects are easier to work on in PHP compared to C#


I have to disagree with pretty much everything you've written, because it seems like you're running into issues of a paradigm shift.

If I'm going to consume a web service, I am going to write the models in C# and let a JSON deserializer like Newtonsoft.JSON map everything. To me, there's nothing better than having a fully modeled web service. I learn a bit about how the service works when writing the models. I know what the data looks like before I start working with it in my own application.

Regarding your web.config note, I guess I don't understand what you're trying to get at. .NET projects tend to throw configuration items into, well, a configuration file. Again to me this is far superior to doing the PHP-industry-standard of having a config.php and chucking a bunch of global variables into it. Putting configuration items behind a parser in a document that you expect the user to edit is good practice.

Development feels natural, every file can be a single class if you want and there are plenty of highly matured frameworks available.

Maybe this is a note more for the NodeJS space, but a single file per class is the general guideline for C#/.NET. Additionally, I've generally found that the .NET framework and libraries written against it tend to be of much higher quality, are more secure, and are more production ready than most I've worked with in PHP land.

On top of that, Visual Studio is a wonderful IDE and is pretty much the gold standard of our industry. I've not had a better experience as a developer than being able to create a .NET Core MVC web application and hit the ground running. I've written anything from 5 line Azure Functions to working with 100k+ line web applications and I'm not sure I could have done it without the excellent debugger available and the very context-aware Intellisense typeahead. In contrast, other than PhpStorm, I find PHP environments to be extremely messy and a bit of a hack to get working properly. If I didn't have some sysadmin background I'm not sure I'd move outside of "debugging" using var_dump().

I was a PHP dev primarily from ~2009-2017 and have been working almost exclusively in C# since.


Ah, but then again, what keeps you from modelling a third-party service in PHP?

We do have config files too - global variables in some config.php was already frowned upon 10 years ago, much more so today. In times of autowired DI, you have a parsable, user-editable config file just like any other project. Had you used PHP since like 2013 or newer, you'd be aware of at least Symfony, which does this since forever.

I don't know a single reason why you would put multiple classes in a single file, especially in times of PSR-4 autoloading. Nobody does this since years, much rather decades, ago.

I also really don't know which libraries you use, but the composer ecosystem is one of the most mature, best maintained out there. There are countless projects of excellent quality out there, used in production on millions of servers every day.

Speaking of IDEs: you mention PHPStorm but still claim there's practically no good IDE for PHP. That doesn't make any sense: PHPStorm is a top-notch IDE, it has virtually anything you have in VS.

And lastly, why would anyone still bother with setting up an environment on their box if we have Docker? It's 2020, there's really no more reason not to.


> Additionally, I've generally found that the .NET framework and libraries written against it tend to be of much higher quality, are more secure, and are more production ready than most I've worked with in PHP land

Unless you've a solid proof, this is just.. blatant lie. How did you measure the security and quality? Was it "ok, this seems nice" or was it literally reading the code, running the tests and hitting the lib with a pentest suite?

See, it's one thing to compare languages (which is silly) and completely another to let your subjective feel get in the way of objective analysis.

Stating that libraries which contain more than 1 class per file are more secure and robust is just a nice wish, but nothing more than that. It's simply not true to the point it's funny :)

> On top of that, Visual Studio is a wonderful IDE

It sure is, top notch IDE.

> In contrast, other than PhpStorm, I find PHP environments to be extremely messy and a bit of a hack to get working properly.

You've PHPStorm and there's VSCode. PHPStorm is better. It works almost flawlessly. What's an IDE got to do with environment? Why are they a hack?

I'm a dev who started with PHP in 1998. and have been using it since (among many other languages). Reason I'm writing this (despite hating it) is to nullify your experience as any sort of valid argument.

Unless you can provide actual, hard proof for what you wrote - it's merely how you'd like it is.

Now, is any of that important? It's not. You use C# and you're satisfied. That's all that matters. If some other guy says PHP is better - you know that it's not, in your particular case. And that's great.

IMO, as a PHP dev, I consider C# an excellent language. As a sysadmin, I hate Windows and its ecosystem from the bottom of my soul.


> Unless you've a solid proof, this is just.. blatant lie. How did you measure the security and quality? Was it "ok, this seems nice" or was it literally reading the code, running the tests and hitting the lib with a pentest suite?

Yes. Additionally features of .NET binaries such as signing tends to be a bit more favorable to me.

> Stating that libraries which contain more than 1 class per file are more secure and robust is just a nice wish, but nothing more than that. It's simply not true to the point it's funny :)

That's not what I was stating. I was stating that 1 per file is common in .NET land and I personally believe that it leads to more organized code.

> You've PHPStorm and there's VSCode. PHPStorm is better. It works almost flawlessly. What's an IDE got to do with environment? Why are they a hack?

VS Code isn't an IDE, really. It's a text editor with extensions. I was speaking more to the fact that setting up a proper development environment with PHP is a chore. If you're using an *AMP, you've got one shared environment across all your development projects. Things like debugging two PHP projects at once can't happen. Edge case stuff sure. Using vagrant or another VM solution is a super heavy way to accomplish something that should be simple. Using Docker is nice, but has its own pitfalls. I agree PhpStorm is fantastic. It's always been one of my favorite tools. A bunch of its editing features are leagues ahead of VS. Unfortunately, it's not a complete solution to a dev environment. And yeah, I'm aware you can launch `php` directly from PhpStorm. I usually find that to be a nightmare in its own way.

Again, I started as a PHP dev and it holds a certain place in my heart. I'm not sure I could ever find an instance to use it over any other platform, though.

Also, you should try to give .NET Core a try. It's a pretty fantastic platform. Like PHP, I would never choose to start a project with .NET Framework.


> [PHP is] so fast and elegant to consume a (SOAP or REST) webservice.

I would never choose PHP to consume a SOAP webservice if I could use C# or Java instead. And I say that as someone who's been consuming SOAP with PHP since 2001, from travel industry suppliers, major CRMs/ERPs and a bunch of quirky services.

PHP's SOAP library just isn't very good. From what I recall it doesn't support some of the security extensions natively, struggles with namespacing, has small changes to data structures when serializing/deserializing (I recall attributes/values being a pain to setup) and worked with some endpoints but not others. That could be the endpoints' fault, but when Microsoft is producting it - I sure expect the endpoint to work with PHP's bundled SOAP library.

Multiple times I fell back to constructing the XML myself (sometimes with the DOM builder, other times with handcrafted XML strings that were tested in SOAP-UI until they worked and given placeholders for data.

Last week I had to investigate ow a service had got the wrong data, and neded to load the XML response again to see the data in our app. The PHP XML extensions give a different structure to the SOAP extension; to get back the result you have to mock the response in a subclass of SoapClient, feed in your XML and let the extension parse it. That works, and is elegant in a way - but it could be so much better.

Rant over ;)


PHP is already one of the fastest languages. Hopefully JIT will make it even faster.

Currently it places #11 on the famous framework benchmark:

https://www.techempower.com/benchmarks/#section=data-r18&hw=...


There are just so, so many problems with these benchmarks. (This comment from the author of Servant, a Haskell framework, nicely sums up a lot of the criticism: https://www.reddit.com/r/haskell/comments/6b3dlt/techempower...) But cherry picking the single query benchmark in particular makes the issue worse. Like... how many web apps do you stand up where you have one client you want to serve? At least the "multiple requests" benchmark is sort of plausible for the kind of workload you'd want to handle.

In most cases, though, you care a lot more about the 95th or even 99th percentile response times than you do the mean; I'd trade quite a bit percentage-wise off my mean response time if it brought the 95th percentile way down.

(This isn't to hate on PHP; PHP is fine. But you shouldn't choose it because the "single query" benchmark says it's fast.)


While I agree that benchmark are somehow problematic, many of the critisms in the Reddit comment are pretty void once we do not targets a browser or theory. When I have an IoT device I do not care about content negotiation or the content type. I send my stuff up using some HTTP I use.

Is it fair in the comparison? Nope. Comparing oranges with apples is always bad. The question however is whether you want an Apple or an Orange?

TechEmpower has to be read like that: plaintext ensures the HTTP server stack and the base runtime. Json is about json encoding and emitting. Single query and multiple query about streaming data through. The benchmark is gradually testing your platform. .NET Core was bad at Plaintext. Now they are top 10. Now they realized the default json library (Newtonsoft.Json) of .NET is very nice but too slow. So they built a new one (System.Text.Json). Now the PostgreSQL Driver sucks. So they find and support the driver project. Like that you built a platform which is top notch.


> Like... how many web apps do you stand up where you have one client you want to serve?

I think you confused "single query" with "single request". The goal of the benchmark is to make one query to the DB per request. The number of requests (clients) is in the hundreds of thousands.


That is a bit misleading: Let me explain...

#11 in Single Query is: Swoole, PHP, mySQL

Swoole => Not default PHP but a highly specialized framework Single Query => This is not about fast language/runtime but fast DB driver

While still definitely impressive, Techempower Plaintext is more specific (runtime + http server). Here Swoole/PHP is #60. The Swoole/PHP mysql driver (that is not default PHP mysql driver) is very optimized compared to e.g. the .NET Core postgreSQL driver. The result => Swoole/PHP is wicked fast (~ 15% delta) but .NET Core beats Swoole/PHP Plaintext (~ 75% delta).

Plain traditional PHP is not one of the fastest language/runtime. But Swoole is a wicked fast framework.

Good thing however: Indeed, the JIT will improve the PHP language/runtime. And Swoole shows what is possible if you make some radical design decisions (same what happened with .NET). And this is good for PHP.


I don't really understand that benchmark. How can swoole (#11), written in PHP, be faster than PHP itself (#125)?


Swoole hijacks network I/O from Zend Engine. Thus, it's capable of performing async I/O while keeping the userland code the same. What the benchmark shows is what happens when there's non-blocking I/O when speaking to the DB. PHP's problem is its synchronous nature, but Swoole easily bypasses that limitation.

Btw. Swoole is not written in PHP. It's C++. It's compiled as an extension for PHP.


Because it's not PHP it's C++.


Because Swoole is a framework with an independent HTTP server and mysql driver. If you get rid of this two, it is just the algorithmic power of the runtime of PHP which factors in here.

swoole is co-routine based, having a much better lifecycle and resource sharing as a consequence. Which leads to much more throughput.


Is there a key for the different language colours? I figure PHP is blue because of Swoole, but the rest are just a sea of colours I have to Google the web framework of to find the language (on mobile at least).


There's a column called "Lng" that shows an abbreviation of the language.


Honestly php seems like the common cold... an annoyance that is everywhere and treated with little seriousness. However every evolution it gets better and stronger and adapts other learnings from other languages. It really shouldnt be treated as a joke any more.

Ps: I love php and jquery... not for any real saas systems but no other tool set allows me to spin up and prototype full web app prototypes in sub 90 min. As a senior tech manager php and Jquery allow me to show functional prototypes quickly and easily get buy in from other department stake holders.


PHP hasn't been a joke since PHP 4, when it pretty much supplanted Perl, which until then had been the dominant scripting language for the web. Its deceptive simplicity has been both its strongest and weakest point. On the one hand, it helped draw hordes of young developers into the field. On the other hand, it gave a lot of programming power to a bunch of people with very little programming experience, leading to the image of a buggy joke of a language.

I don't think who has had a serious look at PHP would call it a joke these days.


> As a senior tech manager php and Jquery allow me to show functional prototypes quickly and easily get buy in from other department stake holders

I totally get it if you prefer to leverage your knowledge of jQuery, but modern JavaScript is just as quick to use. Eg, `fetch`, `querySelector`, and many more. Combined with modern css with flexbox and grid, and prototyping becomes very quick.


I think the comparison is not between jquery and native Dom functions but between making something quickly with jquery compared to using angular or react for example


> I think the comparison is not between jquery and native Dom functions but between making something quickly with jquery compared to using angular or react for example

Probably. I was just making the point that jQuery is no longer needed for most use cases. Lots of folks have no idea what the latest browsers are now capable of.


I'll admit as I moved into managmemt js has also improved. These prototypes are tossaways so it's just faster for me.to grab jquert.

(Btw I love react and use it in any serious project... but each to definitely has its place)


It might be just as quick.

But using modern Javascript frameworks makes you completely dependent on Javascript, unless you want to put in some effort to get server side rendering working). And as every good web developer back in 2009 could tell you this is a bad idea as it makes sure the app can never approach the gold standard: to work in every browser (and work better in modern browsers). In fact it is so bad now that we are repeating the IE6 problems even though all major prowser have all the APIs we could only dream of back in 2009.

Here's a secret: I'd say it is still a bad idea to use Javascript application frameworks on most web sites, and possibly many web apps but it is really nice for consultants, training providers and developers who need job security ;-)

As a full stack developer and a consultant who care about the web and about my clients there are times when I can recommend frontend applications but mostly I just hold my nose, accept what sales have agreed with the customer and try to make the problems as small as possible ;-)


First of all, I wasn't referring to using any JS framework. I was talking about vanilla JS. Did you know that you can use JS modules now in every major modern browser (Chrome, Edge, Firebox), with no build tool required? Now of course, for production deployment, you'll want to do a build so you can hit older browsers and less common browsers, and/or for performance reasons.

And yes, for "brochure sites", nobody should be using anything except for a static site with bits of progressive enhancement Javascript. Agreed.

On the other hand, you use the word "app". For a true app, you're going to need a JS framework. Trying to build an actual app, like Gmail or Slack, is a fool's errand using only server-side rendering. It's possible, but why would you want to do that to yourself? And even then, the user experience would be awful.

I really think web devs need to do a better job both among themselves and for the clients in differentiating between informational sites and brochureware, and true web applications (usually desktop app replacements, or related). The former should be built using static site generators and just bits of JS, whereas no-one is going to try to build a Slack competitor using a static site generator. There are a few projects I've seen that fall in the middle of the two, but those are relatively rare. Most of the time it's very clear if you're building a site or an app.


I think you misunderstood. The previous poster meant modern Javascript WITHOUT a framework. These days I would just go with AlpineJS, tbh. It’s a mini-framework that solves the most common problems. Best thing for people who don’t want to write js at all.


>but modern JavaScript is just as quick to use

this is not true. There are many APIs in JQuerry that are shorter, nicer to use and totally missing in pure JS. there are JQuerry methods that workaround HTML5 and old HTML(quirks mode) differences, there are functions like wrap,unwrap, sibling, parents,find,is,css that replace many lines of vanilla JS.

I am not saying that JQuerry is the tool for building a complex SPA , it has it's uses and vanilla JS is inferior for those uses, for a simple form where you want to check the input JS is fine.


1) It's jQuery, not "JQuerry". I've been using it since 2008, and Prototype.js and script.aculo.us before that.

2) For quick prototypes, I can't imagine why you'd need to accommodate pre-HTML5 HTML. We're discussing quick prototypes, not production sites targeting browsers going back a decade.

3) VanillaJS equivalents are slightly longer than jQuery snippets, mostly because the API names are a bit longer:

css:

    // jQuery
    newDiv.addClass('foo');

    // Vanilla
    newDiv.classList.add('foo');
siblings:

    // jQuery
    const nextElement = $('#wrap').next();

    // Vanilla
    const nextElement = document.querySelector('wrap').nextSibling;
etc etc.

If the extra verbosity bothers you, you can always alias `document.querySelector` as `$`, or `sel`, or whatever. Then you get stuff like:

    // jQuery
    const nextElement = $('#wrap').next();

    // Vanilla
    const nextElement = sel('wrap').nextSibling;
And yes, the jQuery method names are a little shorter, but for quick prototyping, I'd rather use something that I know can be run on any modern browser, with no build step or library required. For production apps, I'll 99% of the time use a framework, either React or Vue.js.

I get that not everyone prefers that. That's OK.


You chose the functions that are the simplest , maybe this are the ones you use but there are many more, like do this in JS. i gave other examples like .is("Lvisible") .parenents , wrap, unwrap, and the one I use a lot .css() .after(), .append() etc . and what makes the API neat is you can chain methods where DOM APIs return special collection that you have to use with for(i = 0; ....

JQuerry might not be the tool for your job but this not makes the fact it's API is nicer, powerful then pure JS . check the anti-jQuerry page http://youmightnotneedjquery.com and you will see that in the end you have to reinvent yor own jQuerry


> JQuerry might not be the tool for your job

Again, jQuery. I'm a little skeptical that you use either very often if you don't even know how to spell it. `jQuery` is literally the global namespace for jQuery (often aliased to `$`).

> and the one I use a lot .css() .after(), .append() etc

after:

    // jQuery
    (target).after(element);
    // Vanilla JS
    target.insertAdjacentElement('afterend', element);
append:

    // jQuery
    $(parent).append(el);
    
    // Vanilla JS
    parent.appendChild(el);
css:

    // jQuery
    $(el).css('color', 'black');

    // Vanilla JS
    el.style.color = 'black';
That jQuery equivalent page is like 5+ years old. Now, there are easier APIs for the few lengthy vanilla JS that remain on that page.


>el.style.color

is not equivalent with .css()

About my typo , I am not a native english speacker and words like query , queue , still, until are hard for me to remember when to double some letter, spell checker will help but jQuery is not in the dictionary and when I code I use $ and never the full name.

In my use case jQuery is the best tool and I am not sure why you need to contradict someone with daily experience , is so hard to admit that the API is nicer, that it fixes browser differences ? Do you lose some points or pride or other ego related stuff? Do you think you win some credit when you find a typo and use that to attack me? Can you explain what is happening in your mind when you type this ?

Go on that page and look at /is() pr /widthy() and not cherry pick stuff or incomplete implementation like you did for .css()


> >el.style.color is not equivalent with .css()

How is it not equivalent? Please be specific.

> In my use case jQuery is the best tool and I am not sure why you need to contradict someone with daily experience

Dude, you're the the one who challenged me, and suggested I was lying or uninformed. jQuery is fine to use, I totally understand someone who wants to leverage their background in it. By the way, I also have daily experience, used jQuery for 10 years, am a senior frontend dev.

But it's misleading to new developers to claim that modern JS doesn't have the same capacities. Making this claim spreads misinformation.

> is so hard to admit that the API is nicer,

Disagree. It's more or less the same. I get you're used to one, but there's not a huge difference between the two.

> that it fixes browser differences ?

Yes, it fixes old browser differences, and I made that point repeatedly elsewhere in the thread. For production apps (apps, not sites), if someone is stupid enough to avoid using a framework like Vue.js or React, and you're targeting browsers going back a decade in time, then it's wise to use jQuery. jQuery is also good for progressive enhancement on brochureware sites if you have to support very old browsers (for those kinds of static sites, no need for a JS framework).

But none of that applies to the discussion we were having. The discussion was about quick prototyping.

> Do you lose some points or pride or other ego related stuff? Do you think you win some credit when you find a typo and use that to attack me? Can you explain what is happening in your mind when you type this ?

Sure. Mostly, I'm annoyed at being corrected about jQuery by someone who can't even bother to spell "jQuery" correctly. I speak several languages, and make an effort to use them correctly. Also, language mastery is irrelevant: it's frankly surprising to meet a developer who has such trouble with basic syntax issues.

All the criticisms you threw up in that last paragraph, also apply to you. Do you even realize that? You're the one challenging my perspective. I'm defending it.

Also, in terms of cherrypicking, I'm using the example you chose. So if anyone is cherrypicking here, it's you.


OK, I will try to calm our discussion down.

The .css() function can be used as a getter or setter , so if you do something like

el.css('font-size') it will not only do the inline style check as your example, if that is missing it can get the computed css style. Also if you check the MDN page https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement... you will see that IE is mentioned because it is a bit different in behavior.

So here is what I see as facts, let me know what fact is wrong and why

- pure JS most of the time you need more lines of code to do the same thing, more lines makes the code less readable

- pure JS does not chain nicely as jQuery, the code is such less elegant and harder to read

- to solve the above you probably consider writing your own mini jQuery, your version will probably be smaller but it will probably miss corner cases and your code will be harder to read for other developers.

You are probably imagine I am wrinting some horible jQuery code to create complex web pages, I am not using it like that(I think React is something that would fit complex GUIs and server side templates in any language for simple stuff ). The problem I am solving is this: the input is any html from the web, fill with garbage and broken tags, I need to do something like "Reader mode" to clean it up (I use the Moziila library for this) but add some more cleanup on top, then I need to transform it in a more strict version of html because my output needs to pass some validator, so I need to find and remove illegal elements/attributes duplicated IDs, fix different garbage ... ideally all the garbage is removed and you get pure text and images, only P,span and img tags (it is more complicated). I also want to present the result on screen and let the user customize some styling.

For new simple project pure JS is enough, for more complex SPA you probably want a framework, there might be some cases where jQuery can work fine, maybe server side rendering where you need a bit of JS for small interactivity (not on SPA) also there are still some good jQuerry UI widgets around,

Can you tell me where is the anti-jQuery sentiment is coming from and if you feel the same for lodash or similar helper libraries?

Sorry for my language I am not as good as others with some of english weird syntax and is harder to write my thoughts


Modern JS is a total shit show of competing build tools, APIs that only work in certain ways in certain places, NIH reinventing the wheel. Thankfully there's some standardisation now, mostly due to the heft of Facebook, but it's still some much more work than it needs to be, espeically on the server compared to other web stacks like Elixir Phoenix, Rails, Flask, even Laravel (despite it's frustrating APIs).


I'm talking about vanilla JS, no build tools.

Totally different than server-side coding.


but modern JavaScript is just as quick to use. Eg, `fetch`, `querySelector`

That's one, trivial, part of JQuery. The real strength of Jquery is the countless UI widgets and libraries built on top of it. I can knock together a quick and easy UI using Jquery, Bootstrap and a handfull of Jquery UI widgets faster than with just about anything else.


Yes, I know. I used jQuery for 10 years.

Now, after learning new APIs for 2 years, I can put together a quick and easy UI using vanilla UI and CSS as fast as I could with jQuery. Particularly grid and flexbox have made a big difference (they fill the role of the old grid CSS frameworks, including that part of Bootstrap).

Your mileage may vary.

Also, the majority of third-party jQuery plugins are no longer maintained. Most of the JS world has moved on.


jQuery: include this lib, modify DOM.

Modern JavaScript: traveling menagerie of package managers, compilers, build tools, etc. Now that is all in place, modify DOM.

At least, this is my impression from the outside. The last time I actually wrote js was around a decade or more ago.


As someone who is not very familiar with JS in its multitude of variations this is what it feels like to me. Somebody told me to try Vue and while reusability of components is surely nice to have I feel kind of lost when all I need is a popup when a "save action" was successful.

What about jQuery? Is it still the go-to for simpler things?


> What about jQuery? Is it still the go-to for simpler things?

Unless you need to target older browsers (like any IE, really), I'd just use vanilla JS. Vanilla JS means no packaging or build process needed. Just create write a JS file, reference it in a script tag in a basic `index.html`, start a web server (like `python3 -m http`) and you're good to go.

Spend a little time learning about flexbox and grid CSS APIs, and you don't even really need CSS framework if you're a decent designer (if not, use Bootstrap or some other CSS framework).

If you're targeting older browsers, like IE, then yes, it's probably a good idea to use jQuery and some CSS framework like Bootstrap.

Absolutely no need for Vue.js or React if you're just doing a very basic UI (however, note that basic UIs have a tendency to become more complex with time, so for that reason most JS devs start with something like Vue.js even if it's not needed initially).

(I'm a senior software developer working in frontend development exclusively for the past 5 years, but have been using JS since 1998, and jQuery since like 2008 - I left the software industry for a number of years after the dot.com bust and came back a decade later).


I'm referring to vanilla JS and CSS. Literally just write a file and go. No packaging. You can even use modules on modern browsers.

A lot has changed in the decade you've been away from JS. Yes, there's a whole build infrastructure now for large-scale project, but bare, plain, vanilla JS and CSS have more or less built-in most of the features of jQuery and the old CSS grid frameworks.


The parent comment is referring to vanilla JS. Just write and serve .js files.

The tools you mentioned are common for frontend frameworks and such.


One of the biggest complaints I've read about PHP is that many things are not consistently named (having never used PHP, I might be wrong). If this is true, are there any plans to fix this?


It is true and no I don’t think there’s much talk of changing it. There’s also a problem with inconsistent method arguments. Just look at array_map[1] and array_reduce[2]. This is just the one example that bit me the most, but there are other inconsistencies like this all over the language that require you to constantly look things up.

[1] https://www.php.net/manual/en/function.array-map

[2] https://www.php.net/manual/en/function.array-reduce


Array map takes one or more arrays with a callback, so the arrays have to be on the end.

Array reduce has one array as a parameter, as does most of the other functions and they all have the array as the first parameter.

Its only one function, and its an inconsistency for a reason. Lets not blow it all out of proportion.


I remember reading a cogent explanation for this inconsistency but can't seem to locate it.

JavaScript suffers from inconsistent mutation/return of array values in array functions, too.

PHPs design problems are mostly being swept away; it's the legacy that keeps its reputation down.


Rasmus Lerdorf has talked about it in other videos but this is one https://youtu.be/iGOAQli7tGc?t=1485

Basically, groups of functions are consistent: string,array etc. Their parameter order was usually based on whatever the underlying C API was.


I use an editor that has the php help built in to not get confusing errors. You type the beginning of the command and it directly tells you what part is the needle and what is the haystack.


I just encountered this last week.

I had to explain to my fellow non-IT students why I was making loud gasps of confusion.


In practice it hasn't been a problem for me in a long time (I've been doing PHP since PHP3 so I have some perspective on it).

First the documentation is fine and easily accessible, second your IDE will hint you the correct order and finally in a real world web framework situation you don't even use those functions that much anyway.

My biggest complaint would in fact be the concurrency situation, it's still not easy and relies on external libraries that feel half-hacks. I guess Elixir spoiled me in that regard.


And when enabling strict types you will get an error anyway if you have the wrong order because the types will not match.


"My biggest complaint about this language I've never used is something I'm not sure is true. Is it?"


Well, I have worked as a web developer for 20+ years. I've heard that PHP is inconsistent dozens, perhaps hundreds of times. I've just never verified it myself since I've never used PHP.


Maybe the Hack language?


PHP 5 was what made me make peace with PHP.


You should try PHP 7 then. Whole other world.


I have and can advise it.


It never should have, the treatment php gets mostly feels like people finding it "not cool enough", seldomly I've seen someone have a real reason to avoid it


PHP fans don't do themselves any favors by dismissing the criticisms in this sort of non-substantive way. The "fractal of bad design" paper has a lot of good criticisms, and the standard library is still a horror show of poor API design, in my opinion.

The first embarrassment I could think of off the top of my head is still there, for example:

https://www.php.net/manual/en/function.htmlspecialchars.php

Completely ignoring the fact that that function is a misnomer because it encodes XML special chars, not HTML, the "double_encode" parameter is pants-on-head ridiculous and basically a concession to people who can't be bothered to keep track of whether their string is already escaped or not and want to be able to pass it through this function again "just in case."

This is a bug waiting to happen (or more like a bug that's already happened all over the web), and the type of stuff that makes seasoned programmers who appreciate a well-designed ecosystem dismiss the entire thing as amateur hour.


When I used the language (around PHP 5) in the past it felt very inconsistent, and many functions were nearly 1:1 PHP interfaces to C functions. The type coercion also was bad, or the stupid idea of having form variables appear as variables in the language (I believe the defaults were changed to disable it in 5).

Learning the history of the language (and that initially PHP was not supposed to even be a language) explains why things were the way they were.

Anyway the language worked, it wasn't specifically bad, and if you didn't use other languages (excluding JS which has similar issues) you might not even see any problems with it.

Anyway, later they started fixing many of these issues and looks like the language is becoming more consistent (note I don't know if this is entirely true, since I haven't have chance of using newer versions, but that's how it feels from outside.)


My pet peeve: http://phpsadness.com/sad/47

TLDR: checking passwords in php used to rely on using the correct comparison operator. Using the'==' operator would introduce subtle flaws. Using '===', you're fine.


Doesn't javascript have even more subtle flaws? Perhaps other languages as well, not familiar with many.


Yeah; PHP and Javascript are in the same general category of completely insane languages. As was (pre-.NET) Visual Basic, though for slightly different reasons.


You should never have been doing that in the first place, checking password hashes should use a constant time equality check to prevent timing attacks.

Just so happens there is now one in PHP - hash_equals, but even before that you could do a constant time equality check trivially by hand.


That's in the instructions.


Documented insanity is still insanity. A very clear example that was luckily removed quite quickly: php_check_syntax.[1]

> Check the PHP syntax of (and execute) the specified file

This function's name and its documentation suggest completely different use-cases. In fact, it apparently does the one thing I wouldn't expect it to do based on the name. It's insane, and it cannot be excused just because the insanity is documented.

The example given by GP is a lot more subtle, but this is not a good argument to make.

[1]: https://www.php.net/manual/en/function.php-check-syntax.php


I accept that, but I still don't really understand the issue, which programming language can I pick where I don't need to read about what does what, I don't feel any language is intuitive per se?


Seriously, I've worked with coders where English is a second language, they literally had no idea that the combination of letters making up words we recognise were anything but symbolic of the function.


Having to read those to see if a working program is fully correct is a failure on the language's part.


Every time I see an article about new features in PHP I search the page for the "annotation" keyword. To be honest I find it a little bit puzzling that to this day a large part of the ecosystem (Symfony, Doctrine, API Platform) revolves around docblock annotations.


Everything in the Symfony/Doctrine ecosystem that uses annotations does so as an option for those who prefer them. If you don't like them, you can usually just as easily use YAML or XML or PHP configuration.

Most developers seem to like them (brevity, locational grouping of concerns), so they tend to get treated as a default, but they're not the only option or the only one treated as a first-class choice. Like much of new-PHP, this also seems to be something largely borrowed from the Java world, it's hardly something new or invented by PHP.


Doctrine is deprecating YAML support. As you said docblock annotations are treated as default. I would like to add that this is so true by a large margin. To the extend that using alternatives feels like an (undocumented) extra step. To clarify my previous statement: I like annotations. I just don't like how a large part of the community is forced into the docblock hack.


Agreed. Personally, I hate annotations. This is the reason why I never bothered with any tool in PHP ecosystem that relies on annotations. It looks ugly, it feels ugly, it doesn't fit with my mental model - I avoid it entirely.


Agree so strongly. Executable comments. Whose bright idea was that?


I love annotations - but only at a language level. Annotations being hacked in through comments is a dirty and I do not like it.


Maybe check out Laravel. They banned all annotations from the framework. Best decision ever.


Honestly, Symfony & Doctrine are fucked up and overrated anyway, so, sepite them being very popular, I wouldn't use them using some weird feature as an argument. I'd like to see some annotations like in Python, though.


Given how much PHP is used, having a JIT will probably save a meaningful amount of electricity


PHP7 already dropped the load on a lot of servers. It was amazing to see that systems like WordPress became twice! as fast by just switching PHP version.


Don't you worry: WordPress will slow itself down soon enough, at least on the user side with React and Gutenberg.


I'm not sure if I'm inventing things but I think there was a report when facebook introduced hiphop compiler.


Yes hiphop compiler was very fast when they started but shortly after normal php was faster than the hiphop compiler. So the hiphop compiler transformed into hhvm which was php with some really nice additions. But at some point the language inventions got more and more in conflict with the increments in the php language so they dropped php support and its now only using its own language which is a very improved version of php


The main benefit will be for long running php processes rather than stateless web requests. It does open php as an option for other applications which are currently being implemented with nodejs and python.


Typically the JITted code is saved between requests, since it's stateless. This is how HHVM works at least.


The JIT won't be a game changer, at least initially.


that page seems to state that it only works in the context of a single request

unless you've got CPU bound PHP code... it seems like a complete waste of effort


It's a way to promote php for other type of applications. Check swoole and reactphp, they will be benefiting the most.


Also check for memory leaks while you are at it.


It isn't limited to a single request, it's merely pointing out that typical web request handling has more limited potential for performance gains from it.


I am guessing blog author has got some things wrong here. I would expect JIT will be useful in a fastcgi setup.

Edit: to clarify, PHP processes in fastcgi persist across multiple web requests. So seems reasonable to me that a JIT would do useful work here. The JIT could even run while the PHP process in a fastcgi pool is idle waiting for next job.


In Facebook's HHVM, PHP has had a JITed interpreter for well over 5 years that people have used in production for great gains. However, most people have moved back to reference PHP 7+ and I believe HHVM had even stopped supporting PHP (it's main use was as an interpreter for & three closely related Hack language).


> Undefined variable: Error exception instead of notice

Well, this is where the chaff separates from the wheat. There's no small amount of crappy code out there which will WSOD after this. Or actually print the exception because they couldn't even bother to switch display errors on... Of course, no even remotely sane codebase will be affected, but... Make no mistake, this is a good change but it will cause some teeth gnashing.


The article is incorrect - the vote for that was defeated: https://wiki.php.net/rfc/engine_warnings#vote

Undefined variables will now be warnings (and one might expect PHP 9 to reclassify them as exceptions).


Over time I think (hope) this sort of change will help to improve the code that people write.

But I will not be surprised to see some people say things like “PHP 8 broke my code”. Of course, what those people might not realize is that PHP 8 did not break their code, the code was always broken, and PHP 8 is now going to surface the brokenness of that code.

But even with code that people refuse to fix, this sort of change will make the brokenness of that code more apparent to others, and so the number of people that use that broken code will cease to grow. If not entirely, then at least reduce in pace of growth.

That is good for the ecosystem of computing. As a proponent of correctness in computing, this makes me happy :)

We all write bugs, but everything our tools and languages of choice can do to help us reduce the number of bugs and the severity (impact on security) of our bugs, the better.


I think it's really a philosophical question what is "broken". An undefined variable used to have a particular and also well-defined behaviour, now it has a different behaviour.

Personally, I think a lot of these design decisions which some people abhor is why PHP became popular in the first place. In that perspective, turning it into yet another "big bureaucratic language" is very much against the spirit of its existence.


Since the dawn of programming there’s been a schism as to whether undefined means empty versus being a logical error. But deep down we all know what it should mean.


PHP has always warned about this since version 5.6 - if not earlier.

To stop the warnings, configuration would need to be changed in PHP config, or those warnings be silenced by the developer.

Any decent webapp has had this issues resolved a long time ago.

I would suggest that websites that will be effected probably will not migrate to PHP 8 that quickly.


True. I always turned it on while developing. This saved me from a lot of buggy code.

But there are a million questions on the internet about this 'error'. And the answer is almost always: turn the errors off.

And I believe this is the biggest problem with PHP. A lot of inexperienced users with questions that get very bad answers.


"Turn display_errors off" is a good answer for a production website. You will get problems with headers and cookies, if notices are printed before headers are sent. You might also divulge information about your stack to users.

For a development and staging website you do want notices and warnings displayed. For a production website possibly only when testing something.


> For a development and staging website you do want notices and warnings displayed.

Just SSH in and tail the log. Dealing with unexpected output from errors clobbering your headers isn't worth the trouble.

You can also try something like FirePHP [0] if you need the errors in the context of the current page.

[0]: http://www.firephp.org/


In my experience, the kind of crappy codebase this would affect would never be upgraded anyway. Many of them are still on PHP 4!


If you only get this error after installing Sys packages, it is time to upgrade


> The @ operator no longer silences fatal errors

Interesting. There are still some legitimate (well, “legitimate”) use cases for that behavior e.g. with PHP’s native XML extensions.


Are you sure those are _fatal_ errors?


https://3v4l.org/saHj2

However you could just catch Exception. Not sure why a parse error is a "Fatal error".


A PHP parse error (of your code) is a fatal error.

A xml parsing error in the SimpleXmlElement constructor is not a fatal error - it throws an exception.

An uncaught exception is a fatal error.


Union types!

This is amazing to see. So many languages these days agree that functions are good. Now they're all adding type systems of one sort or another.

PHP has always been a bit behind the curve but good on the developers for pulling in a cool feature like this.


# Summary of some of the new changes:

## Union types

Specify multiple types

    public function foo(Foo|Bar $input): int|float;
## JIT

Just in time compiler for improved performance

## Static return type

Return static of class

    class Foo
    {
        public function test(): static
        {
            return new static();
        }
    }

## Weak maps

Prevent blocking of garbage collection for improved memory usage when needed

    private WeakMap $cache;

## ::class on objects

Get class type from object like get_class($object)

    $foo = new Foo();
    var_dump($foo::class);

## fdiv function

When you don't care about division by zero

    fdiv($x,0);

## Concatenation precedence

Math takes precedence in string concatenation.

    // this
    echo "sum: " . $a + $b;
    // evaluated as this
    echo "sum: " . ($a + $b);

## Some others

- Create DateTime objects from interface

- Type annotations for internal functions

- Variable syntax tweaks

- Breaking changes

- Consistent type errors

- Reclassified engine warnings

- Reflection method signature changes

* Note: HN pretty please get improved mark down parsing


I've used PHP from 1998 to 2016.

Things I remember I didn't like about/around PHP:

- too many aspects of the language were dependent on config/php.ini.

- it had errors and exceptions. I just wanted exceptions.

- was not very interesting/useful/great outside web backend.

- mb_* functions were not enabled by default

- it had no decent REPL.

- "reference" libraries had bad APIs or were over-engineered.

I'm not sure about the state of these issues now, but frankly I never felt the need to look back. Good to hear there's still progress though.


I expect to have some time soon and I'm planning on writing a full-blown application in PHP, using nothing but functional style programming. Should be fun.


It should! Have a look at Illuminate\Support\Collection, which you can pull in as a separate package (apart from Laravel).

It makes doing functional stuff in PHP a lot of fun.


You might also be interested in Dash: https://github.com/mpetrovich/dash


NO FRAMEWORKS!!!


NO FRAMEWORKS!!!


Judging by comments I saw and what I had my own clients tell me over the phone/mail, it would appear that there's stigma associated with PHP, mostly due to one super-popular blog post called "PHP - a fractal of bad design". I won't go into rebuttal here, the author of the post did enough damage as it is.

PHP evolved significantly since version 4. Version 5 was the "big" deal, with good object oriented features. Version 7 brought the performance in, so we could get rid of Facebook's crappy HHVM (thank you PHP team). Version 8 brings JIT, however most of the workload isn't CPU bound but I/O bound.

So, here's something for PHP devs:

Swoole. http://www.swoole.co.uk -> this is an extension for PHP which brings in the same primitives available to people using Node.js or Golang - coroutines, async I/O, channels, event loop control and much more.

What it essentially does is turn ALL I/O from synchronous to asynchronous. Without any code change or control structure in form of async/await or promises. Write synchronous code, get asynchronous performance.

From my own experience (I've been running swoole in production for 18 months), the performance gain I saw was minimum 500% to a maximum of 2000% (the numbers aren't a joke).

As for PHP - it's a programming language. You can use it right or you can use it badly. This rule applies to almost any language. There's no language in this universe that can turn a bad programmer into semi-ok programmer or even good programmer. If you haven't got the habits and knowledge, there's no language that can rectify it. I've seen way too many people thinking the language of their choice is to blame, but it was always the person in the chair.

PHP performs well. Ecosystem is quite large and luckily there aren't competing standards. Composer, the package manager, is wonderful. There's plenty of frameworks to choose - for web and for CLI usage. Features are being added, slowly but steadily.

I use PHP with Laravel + nginx, next to Nuxt + Vuetify + TypeScript for frontend stuff. Personally, I really like how the mentioned tech can be utilized to create great apps fast - with structured code, that look good and work quick.

Edit: one of the best and most powerful features in PHP (starting with 7.4) is the FFI - foreign function interface. The option to utilize libraries or entire software, without the need to write PHP extensions, is what's amazing for me (I also need it due to nature of my work).

PHP is way more powerful than people give it credit for. But I guess that's what happens when opinions are formed by looking at titles and number of "likes" or other meaningless numbers designed to mislead.


I like the look of swoole, first i've heard of it.

There is also a complete application server that supports php servlets, message queue, persistence etc. that is well-supported. Its free, open source.

https://appserver.io/

A team that supports Magento, Typo etc. based in Germany wrote it.

You can use either the PHP-FPM or the more interesting is the servlets, because the data is kept in-memory - probably much in the same way as swoole functions.

Its basically enterprise Java for PHP.


I know about appserver.io and I would strongly advise against it (I have used it, along with every other project that tried to use pthreads or bypass PHP-FPM). It's not scalable. It also achieves "performance" by having the same process(es) work on the requests over and over again, effectively bypassing what PHP-FPM does on each request. If you set PHP-FPM up that a child process kills itself after 500 requests processed, you'll get the same performance as with appserver, but it'd scale horizontally. It's a toy and I would never use it in production, the authors made a huge mistake of trying to process requests in separate threads - my assumption is they just learned there's a way to expose threads to PHP userland so they toyed with it.

Swoole is entirely different beast, it's like comparing a skateboard (appserver) to intergalactic starship (swoole). It's not just about the performance as it is about exposing OS primitives and having fine control over I/O and processes.

Excellent find, but luckily - the current tools we've got at our disposal are even better. No offense to people using or working on appserver, some projects are just that - toys that help people learn more.


Have you any view on libev and the PECL ev library? There's been a recent discussion on the php-internals mailing list about whether PHP needs a built-in event based system (https://externals.io/message/108226) .

Having input from you with production experience of Swoole would be _fantastic_.


Yeah, looks like an extension to bring a lot of functionality go has into the php space.


I'm a bit confused. I thought PHP 7 introduced a JIT, hence why it was much faster (in some cases ~5x faster). How is it different from the PHP 8 JIT?

I always assumed that HHVM is what brought JITs to PHP originally, followed by PHP itself.


PHP 7.0 was mainly faster because the internal variable data structure (zval) was redefined such that PHP doesn't need to follow so many layers of indirection and doesn't need a full ref-counted heap allocated data structure for every int and bool in your script.


I believe there were attempts at implementing JIT in PHP 7 which were unsuccessful against the timeline for release. Instead, they did other optimizations and managed to squeeze quite a bit of performance doing this (comparable to HHVM).


I think 7.1 or 7.2 was where it generally beat HHVM.


at least some of the speed bump in 7 came from reduced memory usage. IIRC, array pointer size was reduced significantly - something like 120+ bytes per array entry was reduced to ~40 bytes, so far less memory needed to be allocated and managed throughout an execution cycle. I'm sure there were other reasons for speed boosts, but that is one that's stuck in my head for some time.


PHP 7 didn't introduce a JIT. There was an experiment in the 7.x series, but it never surfaced.


I like that 8 has some great changes coming and the JIT will be a long term win.

I just hope the core maintainers evaluate true async/await constructs for PHP. I also hope that the JIT leads to more significant advancement in PHP and how it manages memory. For all it’s improvements it’s still really prone to memory leaks easily


There's an async framework for PHP in form of an extension, called swoole (www.swoole.co.uk). It turns all of your I/O into async code without any control structure such as async/await. The performance gain is incredible. I experience minimum of 700% performance increase with the same code without swoole behind it. Long story short: run your code using swoole, all I/O is async by default, code appears synchronous so there's no change in your code, performance gain 7x.


PHP is synchronous (if you dont add async extensions). How would you use async await in the language?


reactphp already fakes this with Promises, much the same as JavaScript Promises. Why not make this a genuine language construct. You can even use the async and await “sugar”.

Coroutines would also be a genuine improvement


If this is something you would like to see in PHP, please have your say on the mailing list. There are some discussions, most recently https://externals.io/message/108226


Sure there is also most notably swoole if you want async i would go all in. That said it is going to be so wierd for most php programmers you might aswell hire nodejs people and do it in node where language and ecosystem is all about async.


Maybe, maybe not. The nice thing about adding constructs to a language is that you often can opt in when you do use them. Also, if you have PHP developers, its going to take less time for them to learn async constructs in a language they're familiar with than switching your entire backend to nodejs just to leverage those features. Seems to me like that'd be far more work and cost a lot more.

Its not trivial to just upend an entire system.


I'm going to go ahead and play devil's advocate here and make the argument that iteratively transforming PHP into a Java/C# clone is actually doing a disservice to PHP. The reason PHP is so popular, and it's greatest strength, is that it offers a "simpler" paradigm of development.

Many of the latest RFCs accepted (while I agree are great steps forward for the language) may actually reduce it's foothold going forward. That is, they are not a good fit for the community. I see no compelling reason to choose PHP for a greenfield project if, when used in a production environment with a stable framework, you are writing essentially the same code as you would for Java/C#. There is hardly a feature where an ASP.NET core C# project isn't still miles ahead of the same Symphony/Laravel back-end. Hell, with the new Razor-Pages template, you are essentially writing "PHP" in C#... where you get all of the bells, whistles, helpers, type-checking, generics, pattern matching, LINQ etc that C# already offers!

IMO (emphasis on the "O") they are missing the point. I don't want my PHP application to "look" just like a Java/C# app. I don't want a `Controllers` directory and `RepositoryInterface`s everywhere... I don't want all of the same ceremony it takes to develop a .NET Core/Spring app copied into PHP. What I want is a composition of "scripts" (functions)!

PHP should focus on and develop towards it's strengths not it's weaknesses. Lean in to include. Lean in to $GLOBALS. Lean in to a more functional approach. These are the things that have made PHP so dead-simple/approachable over the years.

You want more features? Fine. Add pre-processing directives (akin to .razor). Allow for files to truly be treated as modules. Simplify/abstract templating into the language better. That is, instead of focusing on the kinds of "features" that better-enable OOP (and move away from a composition of "scripts"), focus on making it easier/better to compose "scripts". Make _that_ safer, clearer, more ergonomic. There are _plenty_ of ways to dramatically improve PHP (as a platform) without simply updating the language semantics. The language was _never_ the draw!

As many of the comments in this thread indicate/imply, PHP isn't chosen because it is such a great language, rather, it is chosen because it offers an extremely convenient development paradigm. PHP is very-much "batteries included" when compared to its contemporaries[0]. _This_ is why people reach for it over and over again. So instead of changing the vehicle (PHP), how about we give it more/better batteries instead?

/devil's advocate

How'd I do?

[0] I have always found the whole "framework vs raw PHP" debate in the community a bit humorous. The "framework" crowd never seems to really understand that, in many ways, raw PHP is a framework. What other scripting languages automatically parse HTTP requests for you as part of the runtime? Or come with a default "routing" scheme? Or offer built-in templating semantics? PHP gives you all three out of the box.


Union types look somewhat handy, especially if you're using

    T|null
In PHP 7, you can still do

    function foo(string $bar = null): void
Which is a little clunky...


In PHP 7 the correct code should be

    function foo(?string $bar): void
Having `= null` marks the parameter as optional with the default being `null`. Using `?string` means there is no default and you can pass in either a string or null.


Yes thanks. A little rusty on the old PHP knowledge off the top of my head.


I'd rather have overloaded function signatures, to be honest.

    function add(string $a, string$b){}
    function add(int $a, int $b){}


You should have '?' string


Is it just me or PHP is trying to become Java? I remember 7~ years ago PHP devs were "mocking" Java and not it kinda feels like its moving there


PHP and Perl are as dead as the Diesel engine in 2020. Somehow they are still everywhere, but it doesn't feel right to start anything new with them.


PHP is looking a lot like Java these days.


Language either dies a hip cool thing or lives long enough to become Java


I've seen a lot of people say this but I don't understand the sentiment, could you explain it?


Either you haven't used Java, or didn't look at the examples in the link.

The code looks similar to Java code, how classes are constructed, extra type modifiers, type access levels etc.


Or I'm surprised at the notion that types in an OO language is the minimum bar for "turning into Java"?

That seems like a nonsensical litmus test.


Other languages that have these but they do look different.

I personally don't see anything wrong with it, but it does resemble Java to me.


The OO model is superficially adapted from Java. The open source community is pretty much following the SOLID / clean code cult. There are of course huge differences but the community acts like we're building a second java and there is no scepticism about it.


wow, even PHP gets union types.

More languages really need to adopt union types.


why does php garbage collect anything when there is a reference ? (weakmaps)


Right now, it doesn't. If there's a reference, then the item is not garbage collected. The WeakMaps change will allow a developer to take a reference to something but say, "Hey, I'm caching this for now, but if you need the space, I'm not married to it."


It doesn't, unless you specifically tell it that it should ignore a reference by using a weakref or weakmap.


Misread that as "new in PDP 8". I was expecting an old-school DEC story for a moment...


I hate php because: even if I used it for ~3 years I had to google how to send GET/POST/PUT ... request. There are lots of ways to do that but each method has its own issues. I'm now using dotnet core and happy with it's orm/speed/infrastructure l/productivity/...


This is exactly one of my points - and don't get me wrong - you're to blame here.

Let's dissect your post a bit: you had to google how to send GET/POST/PUT TO PHP or FROM PHP? Regardless, PHP doesn't care what you send it, you can send JSON or base64 encoded string. It's completely irrelevant. If you used PHP for 3 years and are unaware of basic HTTP communication - how's PHP to be at fault here? The real problem here is that you imagined something, it didn't work like you wanted it to and the next logical step is to blame the language. This is such a bad way of thinking, I genuinely feel sorry for you.

I could pull several projects that deal with input via HTTP in PHP, and they do it more than nicely. Issue is that you're simply - mediocre. And there's no language that can fix it. Btw. my intent is not to insult you, even a mediocre programmer can become a superstar.


I think most other languages and frameworks work via a more declarative API - "if a GET request to /this comes in, return that". I had to look it up / remind myself how it works in PHP as well the other day, and it's a bit more involved:

    - Create a .htaccess file that rewrites /api/x/y/z to /api/index.php/x/y/z
    - Read $_SERVER['PATH_INFO'] for the /x/y/z
    - Read $_SERVER['REQUEST_INFO'] for the HTTP method (GET/POST/etc)
    - Create the response starting with some calls to `header()`
    - 'echo json_encode($resp);'
I'm sure all that is abstracted away in e.g Laravel though. The PHP standard library could also do with an overhaul for modern applications for requirements like this though.


- $_SERVER contains server and execution environment info - $_REQUEST contains request input parameter values (regardless of http verb)

That's it. It's not a lot. They're 2 super simple arrays.

PHP can also work from command line where $_REQUEST/$_POST/$_GET are unavailable. You can also entirely ignore the existence of the above variables. You can read from standard input and treat input as JSON - options are endless. This merely means that the example shown is not entirely correct - it's not "how it works in PHP". It's merely one of the ways. But the real problem is: no one bothered to research it and you blindly assumed that's how it works.

Laravel (Http/Kernel library) standardized the interface towards the dev and that's great. But the input itself isn't as tied to PHP core as your comment makes it seem.


If you're sending GET/POST/PUT requests rather than just receiving them, curl_* methods are pretty easy and well-defined. But there are also numerous wrappers & frameworks that can make the process simpler.


I wish PHP makes the end of line semicolons optional like other modern languages.

It saves a lot of typing when I have to trace brackets after auto completion to add the semicolon instead moving to the next line.


Erm.. no. It's the opposite for me. I've used semicolons for over 2 decades. I can type pretty fast. Removing one character under the guise of "but I type faster" is just pure BS. Without semicolons, I can't work. The person who came with the idea to remove semicolons in JS earned a special place in hell.


In JavaScript the automatic semicolon insertion is almost universally reviled. Why not just have your editor insert the semicolons for you if it's such a pain to type them?


> Why not just have your editor insert the semicolons for you.

They don't insert the semicolons automatically as it can't tell if it's the end of line or I'm about to invoke a chained method etc.

Not sure what the down votes are about as it literally increases 2 to 3 letters of extra typing just to append the semicolon after auto completion.

> In JavaScript the automatic semicolon insertion is almost universally reviled.

Why? There's literally no need except on a rare occasion. My IDE happily gets rid of JS semicolons and it's far easier to type.

Ruby and Python don't need one. Just feels tedious compared to other scripting languages.


I never use semicolons in js except in for loops like for(let i=0; i<100; i++)

In all other places it isn't necessary anymore.




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

Search: