291 points · by doppp · 4y ago · 263 comments
I think WordPress is pushing other projects forward as well. The tech stack over there doesn’t move nearly as fast, but the UX is still pretty good out of the box and with the enterprise clients I work with on a daily basis, they all still love WP.
Back to PHP proper for a minute, the language is fast. There are efforts being made to run PHP on Serverless infrastructure or with continuous process environments. New features are added to the language on a regular basis as evidenced by this post and others. The defacto package manager, Composer, is also world class.
It’s a good time to be a PHP dev!
As a final point, I’ll throw out some of my worries. I’ve been writing PHP since 2010~ as a high schooler fooling around.
The “Java-fication” of PHP is real. There is a push for more types and type related features. These aren’t bad in isolation, but as they move deeper into the core of the language, there is a risk of breaking legacy apps. Historically, backwards compatibility has been excellent and allows older apps to upgrade PHP versions and take advantage of performance improvements without a rewrite. I’m not advocating keeping 100% compatibility forever, but recent versions have played more fast and loose with breaking changes. We’ve done a decent job of carrying the entire community onto new versions and that will be important for continued adoption.
Take a look at the open RFCs for more details. I think there is value for pulling good ideas from other languages, but we don’t need every idea from every language.
Here’s to another 20 years of PHP!
If anything, it's holding PHP back. I don't often work with WordPress projects, but when I have to, it makes me want to cry with how backwards they are. WordPress doesn't even have a real routing system!
Furthermore, its ecosystem just seems to encourage really, really bad things, like user-editable templates, PHP code "snippets" stored in the database, images which should be in themes stored as post attachments instead, and just general lack of respect for the idea of separating code and content. Almost every "plug-in" or template is crippled and begging for license fees and/or throwing spammy "notifications" all over the admin interface. I know this sort of stuff are more culture issues than code ones, but they're still problems, and ones you only really see happening in WordPress sites.
I get angry when a client comes to me with a bundle of WordPress mess and asks me to fix or improve something. It's shameful and disrespectful to take a client's money and give them a WordPress site in return. Do these people actually not realize there's far better things out there?
If their site is already Wordpress and they ask you to fix it, then your job is to fix their Wordpress site. Where is the shame and disrespect in that?
I agree about the spammy notifications and PHP code snippets. But sometimes code snippets can save time. It's better to have 10 code snippets to achieve 10 fixes, than 10 plugins to address those same fixes.
There must be a lot of developers out there paying their rent and feeding the cat from Wordpress plugin subscription earnings. While this does encourage the spammy ecosystem, it also encourages competition between plugin authors to maintain and develop quality plugins that do the job.
> Do these people actually not realize there's far better things out there?
I'd be interested to hear what good replacements there are for Wordpress+WooCommerce? I find WooCommerce slows down Wordpress, regardless of caching plugins and other tricks. It's annoying, and I'm genuinely interested in alternatives with as much flexibility and support?
None. I just finished up such a contract myself earlier this month. I was speaking of building new sites from scratch.
> I agree about the spammy notifications and PHP code snippets. But sometimes code snippets can save time.
Put code in code files, under version control. Not in the database. Not in a blob field that gets eval()ed and is editable by users. This is sane web dev 101.
> I'd be interested to hear what good replacements there are for Wordpress+WooCommerce?
Drupal 7 + Drupal Commerce was very nice back in the day. I don't know the current state of Commerce under Drupal 9 but it's what I'd start looking at first if someone wanted me to build them a store from the ground up. Magento is still around, though I've heard that its code is incomprehensible. And if you're not afraid to take the thin framework or frameworkless route, the Omnipay library [1] combined with standard CRUD for the products should get you pretty far.
What are your credentials with non-PHP, non-JS/TS languages? Have you written some Rust, Kotlin, Swift, ReasonML/ReScript/OCaml, Haskell, Elm or Clojure? Those languages are different to some extend, they take fresh approaches, they contain new ideas and are scrape throat well designed.
I find most cheering for PHP and JS have very little exposure to other camps of software development.
> PHP is probably the best language for server side webdev today.
I'm telling you (opinion ahead), it most likely is not. And most likely will never be. It simply has too many fundamental design errors that have long known solutions, are near impossible to fix in PHP/JS and are fixed-by-design in other languages that also have good tooling for web-dev.
This is not just PHP/JS. But since we are looking at "the best lang for webdev" I limit myself the these and this use case.
I understand you have invested time in other languages, we all have but lets focus on facts not fears of your choice of language seeming less popular.
Please read my comment again. I'm not saying Haskell is the best lang for webdev. I'm just saying that claiming "PHP is probably the best language for server side webdev today" is missing a lot of innovation that is very usable for webdev, and hint at bubble think.
The "best language for server side webdev today" is going to be a matter of taste either way. But when one's saying it is PHP, I immediately wonder what other languages the person has done webdev in: since PHP is not a very nice language IMHO.
> I understand you have invested time in other languages, we all have but lets focus on facts not fears of your choice of language seeming less popular.
So what are the facts that make PHP the best for webdev? I dont think it is often picked for greenfield project by highly skilled teams, when given the choice to pick any language they like. And that would be a fact I'd respect in this context.
> Rust, Kotlin, Swift, ReasonML/ReScript/OCaml, Haskell, Elm or Clojure?
OCaml is an excellent language depending on what you are intending to do. I can't imagine though that it would be a pleasant generic server side.
From a very quick search, it looks like to even connect to Postgres you'd have to manage yourself the connection pools ? https://medium.com/@bobbypriambodo/interfacing-ocaml-and-pos...
The same would apply to most languages on your list, except perhaps Clojure who has an excellent ecosystem thanks to the JVM. But then, is Clojure a good webdev language ? maybe ? I only toyed with it for a very short time, but I don't see it on par with PHP or ruby for instance.
comes to mind for OCaml.
https://github.com/paurkedal/ocaml-caqti
for db code.
Ocaml? Elm? Clojure? Haskell?. That's fun for side projects, not for real business.
Because (1) both very often used in webdev, (2) both have many "adherents" that totally love the language yet have little exposure to languages of different paradigms, (3) are (opinion alert) not very well designed.
I'm aware of the differences between JS and PHP.
I love Clojure, it’s so well designed. Haskell is hard to beat in terms of academic type correctness. But what if I’m trying to build a web app and my priorities were, ease of hiring and productivity, especially for junior devs, and a big ecosystem. Does Clojure win here against PHP? That’s a much harder argument to make. Would anyone say Rust is a better web development language than PHP?
All these tools have trade-offs. PHP is a fantastic choice for web development, the rough edges are becoming increasingly minimal with each successive version.
I'd rather hire someone that knows what they are doing and give them tools to maximize the scale of their strengths.
2 good devs working in elixir, rails or clojure will accomplish far more than 10 juniors working in javascript or go.
Nah, I like to get shit done and make buckets of money.
Composer suddenly got good, didn't it! Composer 1.x was one of my pain points I think.
I can't think of many things that really bug me much anymore.
Null coalescing operators and named parameters are the kinds of things that make me happy.
I also adore Laravel (and particularly Lighthouse).
But what I really like about PHP is the humility and maturity of the whole endeavour. It's really typified by Rasmus Lerdorf who openly critiques his own abilities and seeks out smart people.
This attitude of “what is the best” promotes cargo culting and should stop.
The terse certainty in your response is ironic, is it not?
Considering the parent post frames that as opinion with the word "probably" and then makes a case for the opinion.
For every person who is vehemently in favor of one language over all others, it's usually pretty easy to point out another language that will get you 99% of what that other language will. So it's not a very tenable position to think one language is the be all end all.
But on the flip side, and in part because of the points above, "language cargo culting is stupid and should be avoided in almost every instance" can make a great deal of sense.
This is very interesting, I didn't know this. This is a perfect fit for PHP, as it was always designed with this model in mind, and the programmers that use PHP are already used to this way of developing, as that's exactly how php-fpm and mod_php already work and always have.
Yes, but now you have to pay for every requests made to your app instead of just paying $4 a month for a shared Apache server and I also have to architecture my PHP app in a rigid way to fit whatever "serverless" execution model the SAAS runs with.
This has not been my experience at all. Updating PHP versions _and_ some even fundamental libraries has been very painful and anxiety inducing, you had to be very careful and patient. It's similar to JS in that regard and in some cases worse.
After some arguing with the company that is payed to manage their IT environment she got them to finally update the php version and now the server is running 8.1.
I was glad that at least wp was up to date. Current wp running on quite old php version and exactly nothing broke with the update.
I was positively surprised. Would have expected more problems from my experience with other projects in other languages.
We all know the tech is out of date at its core, but I don’t think it’s fair when people say they’re holding PHP back when there is an active effort to keep things compatible.
I'm not saying there aren't good reasons for _some_ of the changes, including historical error prone baggage. I'm also not in any way try to disrespect the maintainers. But to say PHP is a stable language and ecosystem still does not reflect my experience with it.
https://techblog.wikimedia.org/2020/10/26/impact-of-using-ht...
TLDR they used envoy proxy as a sidecar container. So to your point its a pain but still achievable
All performance issues we have ever encountered were always related to the database - never had an issue with PHP or Laravel.
However, we use Node.js for websockets. Though there are some improvements in PHP for event-driven development (like ReactPHP [1]), it was quite hard to find proper documentation and help to build a production-ready WebSocket server. So, we ended up using Node.js for that.
The new features added to PHP in the latest versions are great. Type hinting and return types are really helpful in writing better code. I hope there will be an addition to type hint advanced data structures (ex: Arrays of Objects) in a future version.
Internal framework PHP monolith, nginx, Aurora MySQL, redis, Memcache, internally developed message queue, handful of small Go microservices.
While we're largely hosted on AWS, some countries require us not to be, namely China, where are product lives on servers run by the government. We've kept are infrastructure non-AWS compatible.
For our US installation, monolith scales up to 50+ servers during the day and down to a minimum of 2 at night.
In total I think it’s something on the order of ~1000 application servers (nginx/PHP) that are specced to handle 28 concurrents, and 200 Percona instances of varying sizes. A big HAProxy cluster sits in front of the whole thing and cloud flare in front of that.
A whole bunch of memcached servers spread around too. By far the biggest bottleneck is the MySQL servers at the moment, so we rely heavily on memcached to keep requests away from the DBs.
- Laravel
- Redis
- PostgreSQL
- Nginx+ php_fpm
I don't even use any of the JIT stuff, but I will soon.
[0] Once I figured out how to configure Caddy, that is. (Laravel vs Caddy documentation ease of use is night-and-day territory.)
Originally a performant was someone who'd performed in something (similar to combatant).
Unfortunately it stuck.
Maybe there’s a way to do them “right”, where they have the same positive impact on code readability. But I haven’t found a font yet which pulls that off.
I’m not a font designer, so this is just using my imagination, but I suspect they’d work better if they still left some space in the monospace grid rather than fully spanning multiple characters. Eg => looks like an arrow but with a very fine gap (1px at any size? maybe 1 device pixel on high DPI at smaller sizes?) between the characters.
And, I think that's really my objection to coding-specific ligatures. When you're used to them, you can "instantly realize what they represent," but they're rarely as clear as simply displaying the characters that you type. Historically, ligatures come from slightly tweaking the aesthetics of letter pairs or triplets to be (subjectively) more readable, never in ways that obscure the actual characters. Coding ligatures are arguably designed to obscure the actual characters being typed. That might be relatively inoffensive, like joining the characters in "=>" to make it look like an arrow, but it's not materially helpful -- and sometimes, like the Three Mystery Lines, it's actively puzzling.
Often doesn't work in practice. I cannot instantly distinguish
• ‖ from ligated ||
• … from ligated ...
• ⁂ from ligated ***
• ⁇ from ligated ??
• → from ligated ->
• ↜ from ligated <~
• ↠ from ligated ->>
• ⇒ from ligated =>
• ⇔ from ligated <=>
• ⇜ from ligated <~~
• ∨ from ligated \/
• ∷ from ligated ::
• ≔ from ligated :=
• ≠ from ligated !=
• ≤ from ligated <=
• ≪ from ligated <<
• ⊢ from ligated |-
• ⋄ from ligated <>
• ⋘ from ligated <<<
• ◁ from ligated <|
• ⩵ from ligated ==
• × from ligated x with hex digits following
& al., but I have to examine the characters in kcharselect, a REPL or similar.
PHP as a language is... okay. It's been modernized to include many of the faculties a developer would expect of a language in 2022. But honestly, I'm ready for the "improvements" to the language to stop. The closer you get to C# or Java the more obvious it is that PHP will never catch up! It's not that it has to catch up, rather, that few people actually choose PHP because the language is so great. If you were choosing a your stack based on "which language offers us the most features or highest ability to express our problem" you wouldn't be choosing PHP!
Here's the secret: PHP is probably the best language for server side webdev because of the runtime! It's so dead simple to develop and deploy PHP. I mean the language itself is basically a web framework right? How many other languages automatically parse an HTTP request and hand it to you by default? Or offer built-in templating semantics for composing HTML? Or have request routing by default? I don't know of another one. That's why I, and many others, choose PHP!
You know what I'd like to see? The trajectory of PHP's development change to lean in to the above -- to focus development on improving the reasons why it is chosen in the first place! I don't need a C# with slightly different syntax (or named parameters). I'd like:
- Improved templating semantics
- A better module system
- A way to bake routing into each file (overwriting the default semantics)
- Adding a built-in service-locator pattern/DI
- A way to make PHP scripts more testable
What I'm saying is just make it a better framework by default. I know I know... "Laravel this, Symfony that, have you heard of Slim?". Yes... I get it. There are community-made solutions to the above problems. And you know what? They won't be as performant or integrated as if the runtime itself was upgraded to make them obsolete. It's not like routing and DI are that complicated (the two most obvious reasons frameworks are employed).
I like that I can write a simple API in PHP without pulling in a single dependency! It makes so many things easier (the right things too). Now let's just extend that to all of the basic facets a modern web framework offers!
The problem with templating systems, routers, DI containers, testing frameworks, etc.. is that they are all very opinionated. There is no one way to do it, and each implementation has upsides and downsides.
On top of that, the PHP ecosystem is so mature that for each of the possible implementations of these features, there is a stable, production-ready and actively maintained library/framework. Why reinvent the wheel?
An important detail is that most of these frameworks have also built a business around their product, which means that people are being paid to work on them. How would the financial situation work if you moved all that into the core?
For me, the current situation is close to the ideal one. For example, the recent addition of fibers into the core in PHP 8.1 was a logical step to allow cooperative multi-threading. It will be used by great userland frameworks like Revolt, Amp, ReactPHP and more. The full event loop feature would be too heavy for the core.
+ Composer is so great that installing any of these packages is a breeze anyway.
PHP scripts on shared webhosting was the original "serverless" and you didn't have to be too careful about object lifetimes and leaking database connections because as soon as the request was finished the entire process was nuked from orbit.
But "modern PHP" is the complete antithesis of everything that I grew to admire about PHP because it's just another Java or C# with awful syntax and weird equality rules and gigantic frameworks with thousands of classes and interfaces.
I would very much like to see a version of PHP that dropped all the nasty namespace and object-oriented misfeatures and just focused on cleaning up the language semantics and enhancing the built-in framework features...
As someone who had to deploy PHP applications: hell no. For developers it might be easy, but for admins, the runtime is nowhere near good. Sure if you think deploying your site using scp, already discovered rsync to do this, or even use the cutting edge way of deploying by using a git checkout on the server, you might think it's great. But that's how you take down sites or have service interruption.
The problem is not that it cannot be done right, the problem is that the runtime enables and even promotes such bad practices, and makes doing it properly harder than it should be. And then we don't go into php extensions, performance tuning, profiling, scaling, ...
I cannot think of an easier deployment paradigm than what essentially amounts to a copy and paste in the simplest case (i.e. what we should strive for), and maybe one or two more steps in a more complex case (e.g. `composer install`).
An entire PHP installation can literally be copied and pasted onto another machine and "just work"(though you may need to fiddle with some paths in the .ini). Similarly PHP is fast enough that it's unlikely to ever be the bottleneck in terms of performance/scaling for 99% of use-cases.
I suppose I can agree that PHP may lend itself well to certain kinds of "bad practices", but that's true for any system if not managed well.
From my pov, manually logging in on a server has been something for emergencies only for a long time now (10y+), and if it's frequently required or even essential to deploy and run an application, this is a sign of bad practices. So the last thing I want to read to deploy some software is "can literally be copied and pasted onto another machine". Maybe you can do that, but you never ever should even have to consider doing this. Where is your versioning, ci/cd (testing, quality gates, automated deploy), how do you roll back in case of a problem? How do you track when new versions were deployed? How do you address patching, runtime differences, active PHP modules and php-level config? What webserver do you use, how does it need to be tuned for your workload? PHP-FPM? Do you expect something specific? Do you rely on .htaccess files? The list goes on and on.
These things are a major hassle at the scale I've had to deploy PHP services. Its best option is containerise them, and then you have a bunch of other challenges due to the process per request runtime design impacting monitoring, metrics, autoscaling, ...
If you want to do something like share some heavily read data across processes you need to then introduce memcahe/redis in to your stack, whereas in something like Go this can be done in your application code. This also means PHP is a nightmare for connection management to others resources like your database - if you autoscale your API you are in a very vulnerable place for maxing out connections on your database as every client request needs to create it's own. You can solve this with something like Envoy I think, but again it's adding more complexity to your stack, more tools to configure and deploy.
This was my main issue with PHP. I found the language itself fine to be honest. Not the most elegant but hardly as bad as people make out.
If you dump your read heavy data into a PHP file on disk, that just has a return of your generated data, you can be benefit from having that bytecode compiled data stored in opcache for free (for the entire lifetime of the php-fpm service, or until you reach the maximum opcache allocateable memory).
I think that PHP gives you a few nice utilities to handle sharing, but they are problem specific. For example you might also spawn threads within a background PHP task, and there is shared memory functionality you can use in that case as well which is going to be faster than apcu or opcache.
And that solves both issues at once.
I guess I started writing PHP when PHP 5 was already a thing, didn't depend on any third party code, and used PDO from the start, so... I guess I was lucky to pick the right abstractions.
$ php -a
php > echo $foo;
Notice: Undefined variable: foo in php shell code on line 1
> This is only a notice error, and PHP will happily carry on. This can be confusing for those coming from “exception-heavy” languages, because referencing a missing variable in Python for example will throw an exception:> The only real difference is that Python will freak out over any small thing, so that developers can be super sure any potential issue or edge-case is caught, whereas PHP will keep on processing unless something extreme happens, at which point it will throw an error and report it.
This is the kind of mentality that scares me about PHP. The author is saying that an undefined variable is just a small thing, nothing to be worried about and the correct behavior is not to "freak out" about it and just carry on. And only stop if something "extreme" happens.
Am I crazy to think that this is crazy? I can't think of a case where continuing with program execution after referencing an undefined variable is a good thing. Trying to use an undefined variable is a bug, a potentially very serious one, so I prefer my language to stop me from writing this bug, not just "note" it.
I mean, we have ways to catch those errors, its just that when they do appear in prod its usually because the project is so low impact (99%) that the budget for testing and whatnot is nonexistant (and the reasons for that vary from project to project, of course).
My experience suggests that, were this error to appear in a more complex component (say a shopping cart or notification system) these "non-entirely static-content-based" parts usually are either separate projects or have their own adequately-sized test code.
"But this is not a website, its a complex web app" - then PHP was probably not the most sound technical choice from the start.
"But this teaches bad practices" - practices are always evolving, new languages appear from time to time. I'd rather work on fixing real world problems.
"But PHP is old!" - so is Java... besides, another name for "old technology" is "stable tecnology".
In short, it is best if there are no errors in your code (haha yeah right..). If there are any, and its a website written in PHP acessing an undefined variable, it is probably a small thing. And if its critical that it does not happen, its usually an engineering blunder. Not the language's fault.
In particular, this exact case you're talking about is being voted on right now, to promote it to an error instead in PHP 9.0: https://wiki.php.net/rfc/undefined_variable_error_promotion
It's looking like the vote will pass (as of writing, 33 to 8 ~= 80%, and 67% is needed).
https://github.com/laravel/framework/blob/master/src/Illumin...
For other frameworks, you can convert warnings into exceptions with 3 lines by implementing a custom error handler.
Every time a PHP post makes it to the HN frontpage, there's a ton of people saying how easy it is to pick up, build a project on, and deploy. I sometimes wondered "hm, maybe I was wrong about it, I might try it out". I had no idea it had skeletons like this hidden in the closet.
With PHP there's no one great way to write templates, there's all just kinda clunky ways (e.g. heredoc or using double quote strings with variables inside).
Take match expressions plus enums. Incredibly useful. You know what's even more useful? When it's a type error to leave out one of the values. This means when you add a new value you'll get a bunch of errors you need to fix. Technically you can get around this with a default case but I consider that an anti-pattern in most such cases.
The Hack type system, particularly the ability to express nullability, is just vastly superior.
Named parameters are an interesting one. The Hack equivalent is to use shapes [1]. This is slightly verbose but you can express what shape fields are required and optional. Javascript manages without named parameters using anonymous objects, which is basically the same thing.
I didn't know PHP lambda expressions can't be multi-line. That seems weird. Again, Hack is simply better here allowing both this syntax and anonymous functions, all of which can be multi-line.
I also find the Hack collection types (vec, keyset, dict) to be superior to PHP's array with more obvious semantics and less weird type coercion. PHP's default of maintaining insertion order is amazingly useful and I'm honestly surprised more languages don't copy this. Of course you have things like LInkedHashMap in Java but doing this out-of-the-box I tend to find more natural.
Anyway, I think the hate on PHP is a trope at this point, largely outdated and just boring. Modern PHP is actually quite pleasant to develop in (IMHO).
I agree the type system is superior, given the language was created to have a type system in the first place (PHP was not).
But PHP has allowed nullable types in syntax since PHP 7.1.
> Named parameters are an interesting one. The Hack equivalent is to use shapes
Hack shapes are not Hack’s answer to named parameters. Instead they’re a way to specify dict contents on a more granular level. A comparable array shape type, expressed in docblock form, is now supported by all major PHP static analysis software.
> Take match expressions plus enums. Incredibly useful. You know what's even more useful? When it's a type error to leave out one of the values.
Most PHP static analysis tools give you this information.
> I also find the Hack collection types (vec, keyset, dict) to be superior to PHP's array with more obvious semantics and less weird type coercion.
Absolutely agree with this, but for now (and maybe in perpetuity) we’ll have to settle for the swiss-army-knife array type.
The divide could be catastrophic and for me, would be a major turn off. Look at JS and TS. Some projects go all in, but then others half ass it with `any` return types all over the place. If the JS ecosystem can come together around TS, it’s probably still a decade out until it becomes the default used everywhere. That gap creates confusion and chaos.
If people want similar languages with more/less features, they can create those communities. Erlang and Elixir are good examples.
I'd actually hate to see a JS/TS divide in PHP. The typing needs to really be a superset of existing PHP and backwards compatible. Such a typechecker should cover at least the following:
1. Point it to a codebase and spit out a bunch of errors/warnings; and
2. Run it at runtime where type checks are logged or a strict mode where they're fatal.
It's not. Unless you have a strict typing on the function in TS, you can't know if you're typing the right member.
This is actually one of the thing in PHP I like more than TS.
It takes no effort to provide meaningful names to parameters from the caller.
Static typing cannot be retrofited into PHP. Core already has hard time with generics. PHP Types will always be just type guards with dynamically typed variables.
PHP also inherits shell's here doc syntax, e.g. <<EOF . Not sure if Perl has that.
Actually PHP started out as a bunch of cgi-bin scripts, if I recall. It was very much "a shell for the web".
It kind of annoys me that they all require $ on the left, whereas shell only requires it on the right, which somehow makes more sense to me, e.g.
a=$b # shell
$a = $b # PHP and I think PerlInteresting - it makes it look like Bash uses $ to “read” from the variable, while in PHP/Perl $ only indicates that the rest of the symbol _is_ a variable.
It does.
>>It kind of annoys me that they all require $ on the left
Larry Wall says he went that direction to make namespace clashing between $dog, @dog, %dog, and "sub dog {}" (scalar, array, hashtable, function) a non-issue.
http://www.wall.org/~larry/natural.html ("Disambiguation")
The dollar sign does kinda look like a loose piece of shoestring, though
with each category had it's own optional syntax, many language will avoid this through context in which the symbol is, thus (+ a 1) equates (+ (deref a) 1), but he meant that it was a choice and not an obligation and some systems used $ or other syntactic constructs.
This is false they are not sigils at all. _ and $ are legal variable names in Javascript.
[0] https://dnlytras.com/blog/modern-php/#Named-parameters
[1] https://docs.phpdoc.org/latest/guide/guides/docblocks.html
A lot of PHP projects are littered with this kind of stuff, and when there's actually some important comment it's easy to miss.
That said, I personally prefer just a paragraph or two of prose over "structured" formats.
They’re a great idea in languages designed with them from the start, but adding them to an existing language makes something that was previously a private implementation detail part of the public contract, and only for certain versions of the language. There are already packages that opt out of considering parameters names part of their semantic versioning, effectively demoting it to a “use at your own risk” feature.
I would almost have preferred it to be added only as a special case for built-in features, which are almost all plain functions and have become somewhat unwieldy in places. Third-party code is more often than not object oriented, and so could easily lean on stuff like parameter arrays or fluent interfaces to avoid the ergonomic issues from having tons of parameters.
So given: function foo(string $arg1, int $arg2=2, string $arg3='reddit') {}
You could called it like: foo('bar', default, 'HN');
You see, I actually don't think I ever used usort in about 10 years (or how long is it since anonymous functions were introduced). Instead, in all of my projects there is an implementation of https://underscorejs.org/#sortBy
The difference is that the callback maps the value to something that is already sortable using other native PHP functions, like an integer or a string. I find it way more intuitive than writing these function($a, $b) {/* try to remember which of [-1,0,1] it is supposed to return */} abominations. So as a solutions to remembering "which of [-1,0,1] should it be" I'd expect just natively implementing in C sane sortBy function to replace this pre-historic PHP bullshit. But whatever, it's a matter of taste…
…Or so I thought until now. Now that I think about it, I see [-1,0,1] callback as something really fucked up. PHP usort (and basically all PL ordering functions I know) can order only linear sequences, i.e. it returns an ordered list. Not even a lattice. Basically this means real numbers (or, more comfortable to use in a PL: strings). And with [-1,0,1] I can define whatever the fuck I want. There's nothing to stop me from implementing "paper/scissors/rock" (or even something much more convoluted) in it, and I have no idea how usort will behave then. That doesn't sound good.
So I'd like somebody to persuade me that I personally need [-1,0,1] comparison model for some use case I apparently never encountered. The only reason I can think of why [-1,0,1] might be better is performance (or RAM, actually), but I don't accept it as a valid argument: somehow even my non-optimal sortBy PHP implementation always turns out to be enough, and if I really should worry about sorting performance, PHP probably isn't the right language for my use-case anyway.
Convoluted example: sort some cars by year then by weight except with all Toyota first
In general it is easy to simulate multiple SQL `order by` clauses with [-1,0,1].
Using primitives you can map each car to something like "0t-1994y-0300kg" (remembering to left pad numbers) and sort by that.
In practice they are equivalent (when used correctly) but it is easier to implement primitive sorting with [-1,0,1] than viceversa.
Sometimes I wish languages would have native equality and order operators on (immutable) arrays, so that [1,1]<[1,2]<[2,0]<[2,0,-1] would work...
And you didn't show anything for which ordering cannot be defined by mapping objects (with any number of parameters) to strings, which is kind of the whole purpose of sortBy anyway.
I did so by intentionally, as i believe that mapping to complex enough strings is enough.
> You can implemnt papre/scissors/rock with [-1,0,1], which is not linear ordering function.
In PHP and in most other languages NaN == NaN, NaN === NaN, NaN <= NaN, and NaN < NaN are all false due to how IEEE floating point numbers are defined so you can have weird stuff going on there too.
With some testing:
$v=[1,2,3,4,5,6]; usort($v,$f);
for:
$f=function($a,$b){ return ($a - $b)%3; }; $f=function($a,$b){ return -($a - $b)%3; }; $f=function($a,$b){ return 1; }; $f=function($a,$b){ return -1; }; $f=function($a,$b){ return 0; };
it appears that once $f($a,$b) is calculated $f($b,$a) is inferred to be -$f($a,$b) and to guarantee $f($v[i],$v[i+1]) <= 0 under that assumption.
But I am not sure... honestly i don't care... I am not arguing that one is better than the other...
I guess it's a nice feature to have, but I tend to forget that it exists. Clearly it's not exactly a new feature I was ever very excited about.
It doesn't help that writing my own sorting callbacks is itself something I rarely need to do.
Or reading their free book https://symfony.com/book
That said, if you care about performance, be wary of shared hosts. Some frameworks, like Symfony, need quite a bit of CPU and IO to build a up a cache to get acceptable execution speeds. Nothing too dramatic, but shortly after setting up a website it may be slow on shared hosts with strict CPU and memory limits.
But shared hosting is a security nightmare. VPSes are super cheap nowadays, it's way better to go with that if you're trying to start/run a business.
For tech businesses, I agree wrt VPSes; but for businesses that run a couple of WordPress sites and where tech isn’t a core competency, you can’t beat traditional shared hosting from an ease-of-administration perspective.
{'abc': 2, 'def': 3}[x] ?? 'default';
['abc' => 2, 'def' => 3][$x] ?? 'default';
PHP's `match` is a kind of functional `switch`. For instance, in the following example, an associative array would induce several useless function calls, and `match` is more readable than a sequence of if+returns: return match ($key) {
"id", "ID" => unique_id(),
"UUID" => generate_uuid(),
default => findExternalId($key),
};['abc' => 2, 'def' => 3][$x] ?? 'default';
['title' => $title, 'description' => $description] = $post;
Also PHP's Composer no longer supports Hack. Hack was supposed to get its own package manager but AFAIK that never materialized.
PHP today is so so SO much better then the blubbering eldritch horror that was php 4/5.
I'm still not going to use it until they fix the ad-hoc/chaotic naming of their built in functions, but it seems there's a proposal to alias all their functions to new names that make sense and are consistent with each other. When that happens php will not just be widely productive, it'll be widely liked too.
What should those negligent people use instead, particularly?
What's your suggestion for an alternative system that is as deployable?
I understand that it is convenient to deploy, but a single exploited vulnerability can turn a web server into a part of botnet, forever. And this has happened, numerous times.
I don't have a specific suggestion for alternate system, but it should have a very clean separation between "code" and "data", and have a very easy way to completely replace "code" part. This can be done with Docker, or deb-style installation, or just a sane design which keeps things separately.
And of course you can do it with modern PHP.. it's just that language makes it so easy to do the insecure thing. "I'll just make an uploads/ right next to my index.php, so users don't have to mess with server config too much" - and bam, you have a vuln. Compare it with Golang, or Java -- you'd have to work real hard to make this kind of vulnerability there.
Aside from WP installs I definitely lock down PHP execution to the single entry point; it's possible to do it with WP too, there are just a few more entry points, alas.
I mean, in the "stances", just as an example -- "a language must be concise"?
Really? It must? I think this is inappropriately assertive. IMO the better JS I have seen has avoided some of the more unnecessary conciseness. And that is before we discuss the worst example of "conciseness" thinking in a generation: JSX.
PHP and its community is, if you want a different opinion, more mature, more pragmatic and entirely less screwed up than Node.js, which is, to borrow the terminology, a fractal of indiscipline.
PHP's developers and its wider community have gone about fixing problems while NPM just seems to create new ones.
(The author of that post is in fact a Python fan, which makes it even more chucklesome when looked at over a ten-year timescale. One of the two languages managed to bring developers along for that whole decade with a campaign of carefully planned major improvements and deprecations, without causing major schisms, and it wasn't Python.)
No, most of the problems listed still exist in the language. PHP Core didn't fix these, they just added more features on top of them.
Take this part:
https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/#...
Can you tell me which assertions aren't true as of 2022?
It warns, will likely become an error in a later version (these are being slowly increased in error level to give people time to migrate): https://3v4l.org/qQdSP
> The [] indexing operator can also be spelled {}.
Not anymore: https://3v4l.org/jtjCj
> Unlike (literally!) every other language with a similar operator, ?: is left associative. So this:
Not anymore: https://3v4l.org/t8io2
Regarding string/number comparisons:
Many of the points in the decade-old article still stand, but the ecosystem around PHP has papered over a lot of the cracks in a variety of ways.
It's a slow, deliberative process to properly fix the most widely deployed server-side web programming language. It's not going to be easy, and it is being done by fairly wise heads.
No one is an island, and "batteries included" only gets you so far. In my mind, PHP is in line with C, with the mindset of "figure it out yourself" in regards to packaging. That's not acceptable.
The PHP internals maintainers don't have the time to maintain a tool like Composer alongside the rest of the language. And if it was bundled with PHP, it would be stuck in lock-step with PHP version releases, which means improvement can only be made once a year, basically. That's not acceptable. Composer wouldn't be what it is if it had to release so slowly.
Is that true? How so?
I'm a long-time PHP dev, but of the issues I can recall regarding NPM, including the recent controversy related to the invasion of Ukraine, I don't see how that sort of thing couldn't happen with Composer some day, and it might just be a matter of time; that it hasn't yet has more to do with the relative ecosystems of the two languages and the developers they attract than anything technical, in my opinion. But I'd love to be proven wrong.
Composer packages are vendor namespaced, so hijacking an abandoned package is not possible (and it is with NPM), some examples like https://www.theregister.com/2021/08/10/github_npm_package/
Composer packages also don't tend to have the "culture" of having a million tiny packages for small functions like left-pad, so that helps a ton too. Mostly because PHP's stdlib is pretty great by default, so lots of things like this don't require 3rd-party libs.
Obviously Composer isn't bullet-proof, someone controlling a dependency of an important project can still cause harm by making a minor version release with malicious code, but it's easier to vet a smaller list of packages in the tree, especially if all you need to do is scan through their code on github.
CPAN is bundled with Perl, but CPAN can update itself to a newer version (try `cpan CPAN`). Similarly, NPM is bundled with node.js, but NPM can upgrade itself to a newer version (on Linux/Unix/macOS by running `npm install -g npm@latest`; unfortunately doesn't work on Windows for whatever reason.) Why couldn't Composer use the same model? Composer supports updating itself (when installed as a PHAR) via "composer self-update". So bundle the PHAR with PHP, and then when you run it, can check for a newer version and print a warning if there is a newer version available, and in response to that warning you can run "composer self-update".
I think if you tried explaining your design choices like that in a technical interview, or to a teammate, they may not be persuaded.
Its not, I dont use Java either, same reason.
> Python (pip)
Python comes with Pip, at least the one I use anyway: