314 points · by brendt_gd · 6y ago · 335 comments
In effect this has an impact on performance but it also helps in ensuring that a bad request can't blow out the whole application from serving other requests like is common in platforms like nodejs where you need to be extra careful. Needless to say this makes php becomes quite viable for production envs, and prevents a whole host of issues that need expertise and careful programming to fix.
Not only does this reduce (1) the likelihood of correctness issues, but it also dramatically reduces (2) deployment complexity because you don't need to migrate a bunch of in-memory state distributed across web backends. Your servers should all be considered dispensable.
In 2020, I tend to bias towards things like AWS lambda for this reason (for low volume applications). By default, there's no guarantee on the lifetime of the serving process and any unhandled exception recycles the process so you're never in an unknown (bad) state. There are of course performance downsides to this (particularly when it comes to pooling connections for things like Postgres), but once you figure that out things are generally smooth sailing.
If you want to quickly do something without diving into frameworks the tooling was easy to setup and rarely fell apart, if ever. There are not many moving parts, you usually have a web server that is very solid and comes with an installer that you hit next next next. Then you have a database server, usually MySQL. Sometimes you would need an extension to work with images, you put it in place by editing an .ini file.
Almost like an Excel for backend.
And yet, I find that PHP apps tend to be quite performant, compared to say Java or Rails (I don't know about node, maybe not compared to node). But I'm not a PHP developer, this is just my impression. And the complaints you hear about PHP, I seldom hear performance. No?
It tried for decades to be one with Doctrine, Symonfy and co, trying to copy the worst of Java EE with every single possible design pattern implemented in these frameworks, XML configuration files and co... The problem is no generics, no private packages makes PHP OO a horrible mess compared to Java (or C#).
When I used composer the first time I really enjoyed it, that project also used Silex a minimalistic symfony2, which I also really liked. But what I found out is that in general it is really terrible to be dependent on others, as Silex was dropped by Potencier and my project is left in limbo, sadly. Its very sad because its one of the coolest things I ever worked on, and its still in use today many years after. But I am worrying that some time in the feature, a vulnerability or problem with Silex comes up, the company will have to rewrite the project completely some day.
I worked alot with Drupal7, absolutely hated it mostly because the hook system was hard to remember and performance of Drupal7 in general was absolutely terrible. Then I tried Drupal8 and though some changes are welcome, some stuff are just so god damn complicated, a task that would have been as simple as a few lines of code becomes pages of boiler plate, EventSubscribers and YML config files.
PHP used to be a good choice because it was rapid application development on crack cocaine, developers were cheap and diverse in skill and background.
I still think there is SOME use for PHP, I personally like it for shell scripts mostly because im so familiar with it. I used it alot the past 10 years for making stuff fast for friends and personal use I guess its also a decent beginner language for web development, though javascript would be higher on my list today because of the obvious front end relation.
Nowadays i develop in laravel which is breeze to work with. A simple framework and you can choose whether to use it as simple as silex, full blown like symfony or somewhere between. I started using it like a silex with controller classes and migrated more and more to the symfony way, but still its really easy understandable for any new developer.
If you need a framework, look for something small, small enough to read thru and understand in one hour.
And that unfortunate school of thought created the Java mythos that spread to many languages, not only PHP, eg JavaScript (everyone trying to write inheritance based OOP in a prototype based language).
Few years ago the mythos changed somewhat to every programming language should be functional.
Thus it is not a specific PHP problem, it is common problem of trend sensitivity in programming culture.
And the funny thing is that much of the critique against PHP, like in this thread, is in the form of "why isn’t PHP like the other programming languages?"
But agree PHP should go it’s own way, it has much to contribute to the world still and it feels like it has started to create its own path again.
It would make a nice counterpoint to all OOP-style web dev languages (Django, RoR, PHP8+framework + routing logic) and all frontend-focused frameworks (React, Vue). Super-simple, super old-fashioned, but rock-stable and easy to kickstart a small website or prototype, and great for teaching (nothing is easier than "drop a index.lang" file in this directory and you have a website).
It does surprise me to encounter over-complicated Java-style patterns in PHP.
I am not sure it would have been practical to turn PHP into a strongly HTML aware template language like Thymeleaf for example, while still having it be useful as a general purpose programming language. IMO, the dream of PHP/CFML/JSP/ASP mixing code with templates just isn't realistically possible.
No it's not a different culture, they(enterprise Java and enterprise PHP) both try to force some IoC container everywhere, except PHP is an interpreted language, it doesn't need a IoC container with with XML/YAML configuration files cause there is no long and costly compilation step to begin with...
Same. I've written some complicated ETL/data transform processes in PHP, and used arrays because the array_* functions are so useful for manipulation.
But keeping track of what keys were available was a nightmare - especially coming back to maintain the system.
Like you I've switched to Value Objects. In many ways it's a pain (the intermediate representation that I'd stick into a new array key and pass to the next transformation - it doesn't belong on any of the objects; and PHP needs the equivalent of the array_* functions for objects) but knowing I can't use the wrong key somewhere makes it worthwhile.
/* @return MyObject */
Returning an array with unknown items has always been bad practice imho.I do all my process automation tasks in PHP and it's been such a pleasure.
<?python
And dump some python code the same what you'd do php and have my web server serve it up. It would be handy, but I'm sure the uses cases are limited.There are probably a few still around
if i have to crunch numbers in a script I like R, or Python w/ Pandas
I have inherited a 12 year old PHP app written by 2 interns. The code was written with Notepad++ (no IDE), no comments except when they copy pasted something from the internet, most variables are single letter and it's the biggest spaghetti bowl I have ever seen.
To add insult to injury I have no experience with PHP (apart from peeking at this code to fix a minor bug here and there). To be fair the app works OK and has done the job for all those years.
This app has never been updated so it's PHP version 4 or 5 I think, it runs on an old Debian 5 VM, it's not facing internet, internal use only. It was supposed to be deprecated last year, but now given our budget (or lack thereof) and the sheer incompetence of our new provider I don't see it happening soon.
Is there a way for me to have an IDE with a kind of "compiler" that would help me convert this to PHP 8 so I can migrate it on a more recent VM? Of course there's 0 budget for this.
1. Definitely get a PHP IDE: https://www.jetbrains.com/phpstorm/
2. Get a step debugger and hook it in: https://xdebug.org/
3. Fix the code style: https://github.com/FriendsOfPHP/PHP-CS-Fixer
4. Run the code through some static analysis tools https://phpstan.org/ https://psalm.dev/
5. Upgrade the code with an AST fixer (might help you update to newer PHP version): https://github.com/rectorphp/rector
6. Add tests to it: https://phpunit.de/
7. Run mutation tests: https://infection.github.io/
The "0 budget" is rough, though.
- Make sure you have version control. So easy to do these days, so often forgotten.
- don't think that the steps above must be done in order, right now.
- dkarlovi mentions tests. Start with 1.) smoke tests like simple selenium tests or something like that. You'll find lots of vate towards it if you look and I admit it has issues but for simple projects like this that doesn't change much it should be fine. Of course of you find something better use that.
- one of the most important things about a good IDE is being able to refactor confidently so you can rename variables to something reasonable as you figure out what they really are.
- the book "refactoring legacy code" might be the best programming book I've read.
My basic procedure when inheriting legacy code is:
- Load the project in phpstorm
- Perform autoformatting so it becomes readable
- Run code inspection to find any obvious issues the original author missed
- Write tests in phpstorm, if not already exists
- Run the code with xdebug, step through it
Adding tests for an app with no documentation requires a lot of effort.
code tests yes. Assuming it's a web app, probably not too hard. Get something that records the browser interactions, and do the common tasks people do (log in, click links, make a report, etc). Having general things like that automated to ensure you can run them repeatedly to make sure basic stuff didn't break unexpectedly will help provide some confidence when making changes.
As others said, vscode with php extensions works quite well (you do need a local php install for intellisense to work iirc?)
As for migrating. I wouldn't aim for 8, that's a hell of a jump to make from 4/5 and just getting to 7.x would give you a few years of breathing room https://www.php.net/supported-versions.php .
First goal, get it working on 5.6 without any deprecation errors or notices, that's a good basis for a "legacy" codebase to be on.
From there, the hop to 7.x is mostly changing any mysql_* calls, avoiding the short tags (use `<?php` instead of `<?' and a few other things found by looking at the migration notes here https://www.php.net/manual/en/migration70.php (other version notes available from the menu on that page).
As for tooling, Rector, phpstan and Psalm might be helpful, but might be more trouble than their worth if you've only dipped your toe into PHP development. Rector can do automated refactoring with some code (helpful for the mysql_* function removal/replacement with mysqli_* for instance). phpstan and psalm are static analysis tools that can help find problems or issues with the code.
Final comment, make sure this is in version control so you can track any changes made and have known working versions.
It gives examples and goes bit by bit through the process of organizing code.
I'm using its suggestions along with a static checker called Phan, which I chose because it attempts to "prove incorrectness rather than correctness."
0. Ignore PHP8 for now. There's much more community support for PHP7, so fix it up to work on PHP 7.4 first.
1. My first task is always to use a code scanner to test if the codebase is PHP7 compatible (or PHP 5.6, or the next version on from whatever you're running). See https://blog.fortrabbit.com/php-testing for an incomplete list (I've used others but haven't got my bookmarks to hand). You'll get false positives but also a good feel for whether there are serious issues.
2. You don't say if it's a CRUD app or an API. If it's the latter: set up a PHP 7.4 box (with a copy of the datastore) and route all traffic to the current production box and to the copy. Save the responses from both and compare they're the same. A simple way to see if the app will work on PHP, and when you find something that's broken, you can fix it, reset the logs, and try again. Hard(er) to do with CRUD, but I have compared the datastore contents before to check they're the same.
3. Needless to say, stick it all in source control if it's not already.
4. For your own sanity, run a code formatter over it if the code is messy.
5. I like PhpStorm as an IDE. It's not free, but the intellisense and refactoring support (and the built-in debugger) are timesavers.
6. Assuming it's not global variables everywhere, that they've used functions/classes(!), then as you fix bits of the code rename the single letter variables and add comments. PhpStorm can refactor variable names, so you see what will change before it happens.
7. If the code's using mysql_* functions, which aren't present in PHP7, there's a shim to make them work: https://github.com/dshafik/php7-mysql-shim
8. Good luck! I like unpicking codebases like this and keeping them running. As a sibling commenter has said, it's an internal system so assuming staff are not going to exploit any vulnerabilities or you have guarded against those already, there is no problem keeping it running internally as-is. So long as you can still recreate the VM from scratch (I have had old packages disappear - now that makes for an interensting disaster recovery plan) and reinstall everything you need should backups fail, you're okay.
Correct, it's not free, but there is a 30 day trial. And... if you want to try it past that, it's $9/month on month-to-month pricing. For anyone working in "western" economies, it's near enough to free to at least give it a trial for a few months. The other 'big' competitors - vscode and probably... eclipse - both can provide value, but I've found the JetBrains stuff provide a much nicer out of the box experience for most PHP folks getting started out that that $89/year or $9/month to try is almost a no-brainer. But have also had people disagree, and almost always spend more than the $89 of their own time (or their company's time) getting VSCode set up with a collection of plugins.
Also worth checking out is a package called Rector (https://github.com/rectorphp/rector) which will automate a lot of this by scanning the codebase and providing diffs so you can upgrade safely.
There is your problem. If it's runs on PHP5 (<?php phpinfo(); // in a php page), it might run without hurdle on more recent versions of PHP... or not, but PHP8 isn't a different language, they just added some stuff on top of PHP5. C extensions might break though, because yes, PHP relies heavily on them as the language is too slow to do anything meaningful like writing a database driver.
there were some backwards-incompatible syntax changes between PHP 5 and 7 though. a client once switched on PHP 7 on his ancient WP website and it stopped working altogether because it used some weird no-longer-supported form of `new Foo`.
Compiler: you are looking in the wrong direction, PHP is interpreted. There were some compilers, but it's not what you need.
Converting to PPHP 8: do you need that? what are you trying to achieve? You can keep the app another year or so it it is working, don't fix what is not broken. There is no way to convert to 8, you need to rewrite it, PHP become more object oriented with each version and that is a paradigm shift there is no converter for.
In my case the upgrade was demanded by security because the latest PHP5 release is no longer maintained.
For an internal app you're much better off just leaving it on PHP 5. Maybe add an op-cache for performance.
What I would like is an IDE experience: everything that isn't PHP8 compliant is underlined in red so I can fix the thing without launching the app every time and see if I broke something.
One thing on automated tools: getting a good result is decently tied in to the structure of your project in my experience. A common scenario I've seen is projects relying on requiring other files as part of their business logic (IE, parent file A includes file B that processes and renders content vs file B including file A that defines helpers and what not). This is especially common when projects use something like index.php?file=whatever for URLs. Most automated tools and IDEs will struggle with this and false-flag undefined variables, etc, because there is no hard include path. There are a lot of ways to resolve this but it depends on your project.
Also, PHP 7 is much more aggressive about warnings on types and various other things. Unless you adjust your error reporting settings, you'll likely see a ton of these when you finally switch. I personally enable them on dev so I can clean them up, and keep them reporting to Rollbar on production.
Objectively, compared to other languages i've been working with it is more than OK. Despite it's lack of "style" it is easy to understand, host, tests, diagnose and it is powerfull for web applications.
I've been working on a SaaS API with Symfony now for 2 years, our metrics are good...
It is a good tool, it builds good softwares
It's essentially sinking in popularity because of bad faith and lack of hype, really sad !
Well, the language is burned for a whole generation of devs, and it's hard to lose the nasty stench once it has settled. A major reason might be that you don't touch again what you learned to dislike. Because you known anyway that it will be painful, why go for it?
> It often comes from horrible bad memories from previous versions or old frameworks.
Those old versions and frameworks are still around. Companies don't lose their legacy fast.
> Objectively, compared to other languages i've been working with it is more than OK. Despite it's lack of "style" it is easy to understand, host, tests, diagnose and it is powerfull for web applications.
That always was the case with PHP. Doesn't say whether it has lost it's old flaws.
> It's essentially sinking in popularity because of bad faith and lack of hype, really sad !
Is more losing because of competition. PHP still is mainly a web-stack backend-language that can't offer much in other areas. But now there are other languages who can equally shine on backend, while also shine on other areas. So obvisouly people go for the language which can give them more, instead of less.
1. Its variables start with $ and that is ugly: I mean, come on, I won't even entertain this bigotry.
2. It used to be better before: This is just pure nonesense, before OOP PHP wasn't good to create any big and well-structured application, it is ironic because most of the bad opinions about PHP come from people who used it a long time ago. Besides, you can still use PHP as you used to, but now you have more tools at your dispossal, You are free to use it as before.
3. It is trying to be Java: Well, sure it is more like Java, only less verbose and easier to write. Developers can be much more productive in PHP. And moving in the direction of Java is not a bad thing as the language moved into the Enterprise space. I worked with Magento every day and I am glad the language is more than Java than it used to be, it means we can organise our code better. Again, ironic that some people who mentioned this as something bad about PHP, then went on to say they prefer Java.
4. Composer has made the language worse: Honestly this is so ridiculous... so now having package managers is a bad thing? I haven't met an actual professional PHP programmer who holds that opinion. All of them like composer, it makes reusing code and creating apps in PHP much easier.
At the very least it seems nonsensical and cargo-cultish: As a non PHP-er, what is the actual purpose of $? In Perl, it indicates variable context (for better or worse, there's more than one, so it has to be indicated somehow). In shell, it indicates the substitution of variable name by its value. In PHP...I draw a blank. It really seems like an "I wanted my language to look like some other language but I had no idea what it should be doing" kind of thing.
https://stackoverflow.com/a/3073818
but because early PHP was more simplistic than Perl it only has $.
Powershell also uses $ for variables.
Regardless of etymology of the $ sign and the usefulness of it, personally I like it because it makes it easier for me when I'm reading code, especially if you are scanning fast, to differentiate variables from symbols. Yes, you can get that with your editor too, but for me it is easier to associate the $ sign with a variable rather than a specific color, sometimes you don't have coloring available like when in command line going thru diffs, cat, nano etc.
$foo = "I am foo\n";
$bar = "foo";
echo $$bar;
This is in the documentation under "variable variables" [0]. This also lets you create dynamic function names: function run_foo() {
echo "I'm a foo\n";
}
$method = 'foo';
$picked = "run_$method";
$picked();
[0] https://www.php.net/manual/en/language.variables.variable.ph...You can get used to that in 10 min and move on with your life, it is not a reason to not pick up the language, it's bike shedding.
I suppose if you are equating extra keystrokes to productivity, then sure. However, Java has vast ecosystems and standard libraries that dwarf most languages. The real gains in productivity are in not re-inventing the wheel for everything. Verbosity has little to do with productivity in the bigger picture.
The productivity point was a secondary point but when it comes to building websites I think people can build faster in PHP although I guess that depends on many factors.
1) 'Language configuration' kept in a php.ini that is usually not shipped with any project. Instead, each project tells you what flags to flip so that it runs, but very often every distribution ships PHP with slightly different flags, effectively making it _very_ hard to have a 100% correct php.ini.
2) 'Deployment configuration' that is additionally present in your FPM/apache configuaration. Again, you have to be told by a project that that these given options (often related to timeouts and request size) have to be set. Many projects just assume you have some 'sane defaults' like things bumped up from the defaults. Again, very difficult to get reproducible deployments of an app, unless the developers are very insistent on documenting everything.
3) Extremely painful to debug. If 1) or 2) are broken and a connection terminates during an upload with some 400 error, the error can be in multiple places: nginx/apache, php-fpm, or the PHP code itself. Each one of them logs to a different place, or not at all. It's difficult to actually understand the _source_ of the error. Good luck. Bring strace.
4) Broken upload model. If I understand correctly, all file uploads in PHP must end up on the local filesystem, and they are impossible to directly stream onto something like S3. This means that my Nextcloud instance will first save a few gigs of data on /tmp, and then only punt it over to S3. Gross.
5) Annoying to host in containerized environments. Both Apache and nginx are the kind of applications that insist on doing a bunch of setuid()s, thereby breaking on hardened containerized environments. Not to mention having to host a nginx+fpm/apache combo per application just seems wasteful, but there's no other easy way to deploy PHP apps in a containerized way that I'm aware of.
6) Configuration woes with rewrites, static files, etc. This is related to 2), in which you have to spend a bunch of time configuring your HTTP server in order to split up requests between static file serving and PHP, set up rewrites, and hope you don't accidentally introduce a security vulnerability.
All in all, compares to something like 'here's a go binary, run it, push HTTP traffic to it, it will serve its own static files, too', PHP is an _extreme_ pain in the ass to host.
So the whole "It's trying to be Java" is more like "What does it offer that's better than Java? Because Java has stuff that is better than PHP."
And I'm saying this as someone who doesn't like Java at all.
It doesn't need them IMO. It brings no benefit to the language, really. They would need to be type checked at runtime, which can become quite expensive. Static analysis is a better option for an interpreted language. Read this answer from Nikita (one of the top PHP contributors) https://www.reddit.com/r/PHP/comments/j65968/ama_with_the_ph...
> doesn't have real data structures
Untrue. See https://www.php.net/manual/en/book.spl.php It's usefulness is limited though, because it's rare that you need those types of data structures for web applications.
> no threads or async
Untrue. All kinds of projects like Swoole (gives you a runtime similar to Go) and ReactPHP (runtime similar to Node) and https://github.com/krakjoe/parallel for lower level concurrency. There's also pthreads https://www.php.net/manual/en/book.pthreads.php But again most of these aren't necessary for most apps because of PHP's request-response model. Useful for one-off services though.
> typed function parameters
Completely untrue. https://www.php.net/manual/en/functions.arguments.php#functi...
> no method/function reference
You do those like this: [Example::class, 'someFunction']
I hate it when people write such blatantly misinformed comments. Sigh.
This sounds like kool-aid. Any productivity gain from reduced verbosity would be minimal. Typing out two extra keywords for your method signature is not going to affect your productivity in any real way in reality.
Lots has improved: ide support, jit, package manager. In doing so it became more mature now joining the realm of more serious, enterprise, languages which had all of this for ages. As such it is also being compared against those languages. At the same time templating is now easier and more cheaply done through static site generators. So imho PHP falls a bit in the middle and it is only kept afloat because of the likes of Magento, Wordpress, and other big products built on top of PHP that thrive by being modifiable by practically any developer.
Do you consider Magento being a framework you are happy to work with? I'm also working in Magento 2 and honestly it's a painful experience. It's a so bloated framework that without cache enabled the development is completely awful.
I'm not sure using a word that has historically been used for people who are racist is the right word when talking about programming languages.
Then when you look at the job market, you get a very different picture of what actually gets used. In my country there hasn’t been a single job posting for all Rust in all of 2020. There’s been a single mention of Go as a “nice to know” PHD job at Google Denmark and there is just a single company who has had openings for Ruby. Hell even with everyone’s favourite Python, almost every job involving it is in DataScience and needs you to be a mathematician first, analyst of some kind second and a programmer third. There are a few django jobs, and good for those guys, but in general, even python doesn’t see that much general usage.
The vast overwhelming amount of jobs that’s been listed in 2020 in Denmark have been for C#, PHP and JavaScript, with JAVA still hanging in there somewhat, though typically bundled with whatever they call JBOSS these days.
So unless you’re smack in the centre of Silicon Valley, I probably wouldn’t worry too much about the hate PHP gets.
Most web stuff need no memory management and can happily live with GC or even with giant memory footprint and reboot once a day.
Ruby is direct competition. One of two PHP major web frameworks borrowed everything they could from it. Even PHP is on Ruby bandwagon .... XD
Weird flex.
So you're saying that an aged veteran in any sport who observes and learns from his younger peers should be looked down upon as being on their bandwagon? Their growth, improvement and continued success should be discounted?
> Even PHP is on _Rails'_ bandwagon .... XD
I fixed that for you.
However for people who have not invested this time and effort it is an objectively worse language than other web focused ones in many dimensions.
PHP is a workhorse for the web and still the most important language next to JS in that regard. But there is a reason it is declining (slowly) as well.
I’d take Typescript over PHP any day, but not Javascript.
That's correct. It turns out that it's also bad, though. People don't like to hear it because I'm "just a hater", and maybe one or two of these issues isn't a deal breaker. And yes, you can write real, useful, applications in PHP, but it's a terribly awkward language with a lot of missing features and sloppy dynamic typing nonsense.
* No (real) async or threads (pthreads never worked on backend and is deprecated anyway for those who always mention it in response to me)
* No generics
* Interfaces must be complied to at class definition (leading to verbose nonsense like the "adapter pattern")
* No const or immutability
* `array` is a shitty hybrid of an actual array and a dictionary and it sucks at both
* No other native data structures beside the shitty `array` mentioned above
* No ability to typehint callable function params
* switch statements use loose equality checks, so you should avoid them
* foreach is broken and leaves a dangling reference
* `array` keys are automatically cast to int if they can be, which is broken and insane. (E.g., if I use `array` as a dictionary and one of the keys is the string "123", it will NOT store the entry as key-value pair: "123" -> $data. It will instead store $data in the 123rd slot of the "array". Iterating this `array` with an index will end in a bad way).
But surely someone will drive by and say that none of these things matter and that an experience PHP dev would never be bothered by any of these things, etc, etc. "You can write bad code in any language."
But... you can always just choose a better language if you have the choice. I feel like people get Stockholm syndrome over their tech choices. It all sucks, but some suck worse than others. Don't tie your identity to shitty stuff like programming languages: "I'm a PHP dev." "I'm a Rust dev." Give me a break.
[1] Being slightly hyperbolic - I won’t deny that you can do good things with PHP, as you can do good things with any tool; and AFAIK it’s still unmatched when it comes to low barrier of entry and shallow learning curve.
(I’m coming from the perspective of someone who mostly uses rust, python, and PHP7.3, with odd bits of Hack - in the past week, PHP7.3 has frustrated me with lack of typed arrays, lack of typed properties [fixed in 7.4! Only took 5 years between the introduction of type declarations and consistent support for type declarations...], and dictionary keys being automatically cast from string to int if they look vaguely numeric. It’s a shame Hack never took off in the open source world, as it’s basically “What if we could reimagine PHP without the legacy baggage?”)
Now it seems like the basic type system is in place, great. This new stuff in the article I'll probably start using it when 8.4 drops.
5 years is an exaggeration, but staying a version or two behind really helps you stay sane.
By the way I found Hack/HHVM thoroughly disappointing. Tried running some fairly complex apps on it and it felt like they reimagined the legacy baggage. Seems like PHP itself borrowed a lot of ideas from it though.
I don't either, but what I also don't understand is why in 2020 anyone would use PHP over many available vastly superior alternatives.
Other than keeping old stuff running, why do people keep beating this dead horse? I just don't get it.
Then there's this, choose boring technology: https://news.ycombinator.com/item?id=23444594
Though, to be honest, I'd probably use PHP over Node even with TypeScript because the Node ecosystem is such garbage.
You just have to really like Laravel, I guess, to choose PHP in 2020. Which is totally fair. I haven't used Laravel, but people do rave about it.
It is ok to have a preference to do non web work with PHP but you owe it to yourself to at least try something else before saying you prefer it over everything else.
There is nothing wrong with $ though. That’s just insane. Also I’m very excited to see Drupal 9 being released with twig 2 support and more recent symfony support. I just think you should at least evaluate other options before saying “everything goes better with php sauce” just like the JavaScript crowd should stop and get some help before using JavaScript for native development and or server side development.
He never implied anything remotely similar.
On a serious note, I find the JS ecosystem more annoying than PHP. Modern frameworks like Laravel (Laravel is nice to work with), PHP is more than enough for its intended use - web applications. PHP 7 has good performance improvements too.
Well, if you had a dollar every time you typed one... ;)
It looked like a dead language in the 5.X days, then there was a resurgence with 7.
It's pretty hard to draw a link between these things and commercial success, but it somewhat unseriously reminds me of Jonathan Blow's warnings that eventually everything is just going to fall apart.
"foo" == TRUE
"foo" == 0
TRUE != 0
NULL == 0
NULL < -1
0 > -1
You have to test the simplest expressions because you can't trust the language to do what you wrote.PHP (and JavaScript) gained and maintain their relevance, despite being inferior languages, because of their historical placement. I'm sure COBOL has improved over the years, and we know it is still used and "needed"... because of its historical placement. But you probably wouldn't use it, either, unless you had to (or you didn't know a better alternative).
Bad developers will write bad code in any language, and they will blame the language for it.
Scala is one of my favorites and yet I saw some really horrible projects. They made such a mess since lots of Java developers rushed into it.
People blame Go for lack of a some features like generics just because they are unable to write clean code.
I also prefer beef steak to catfood, but I admit I have not actually tried cat food...
Exactly this. If you already know PHP and can produce results (mostly CRUD apps) and it doesn't need millions of rps, why do we need to use another language because they are so much better ? So much better at what ? It is like saying "I have a hammer, so everything looks like a nail to me". Not every web app has to be written in Lua/Rust/Go/Julia etc. Each language comes at a cost. No free lunch.
"But why should anyone start a new project in php now that we have so many good alternatives?"
Because everything comes at a cost. You want to use Rust instead of PHP ? Sure, sounds great. Now lets go find a really good Rust developer who also understands how to host it correctly and then if he leaves, can I easily find another Rust developer ? Hmmm. You also need to account for maturity, ecosytem, hosting, maintenance etc which are all real world problems. Building a new shiny toy project ? Go ahead use whatever language you love. Again, it is about cost vs benefit.
I can’t even say what’s wrong with PHP, because— okay. Imagine you have uh, a toolbox. A set of tools. Looks okay, standard stuff in there.
You pull out a screwdriver, and you see it’s one of those weird tri-headed things. Okay, well, that’s not very useful to you, but you guess it comes in handy sometimes.
You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.
You pull out the pliers, but they don’t have those serrated surfaces; it’s flat and smooth. That’s less useful, but it still turns bolts well enough, so whatever.
And on you go. Everything in the box is kind of weird and quirky, but maybe not enough to make it completely worthless. And there’s no clear problem with the set as a whole; it still has all the tools.
Now imagine you meet millions of carpenters using this toolbox who tell you “well hey what’s the problem with these tools? They’re all I’ve ever used and they work fine!” And the carpenters show you the houses they’ve built, where every room is a pentagon and the roof is upside-down. And you knock on the front door and it just collapses inwards and they all yell at you for breaking their door.
That’s what’s wrong with PHP.
https://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
edit: Flickr user @raindrift made an actual PHP hammer, famously https://www.flickr.com/photos/nicoletbn/6949293600
2012 discussion of hammer https://news.ycombinator.com/item?id=3866488
TechCrunch defence of the hammer https://techcrunch.com/2012/07/28/not-that-kind-of-filthy-ge...
A more reasonable analogy would be that there's a standardized toolbox that carpenters use that's weird, quirky and sometimes so bad that you need to know workarounds to use it correctly, but the houses that are being built do what they're supposed to in the vast majority of cases because most of the carpenters know the quirks well.
The question then is, if you're contracting someone to build your house, or you're the manager of a construction company, do you go with the standard toolbox that's used by the X% majority of carpenters, or do you hire carpenters that use more obscure (but functionally "better") toolboxes while running the risk of now ending up with unmaintainable or deviating houses that are hard to recruit additional carpenters for because they refuse to work on what is quite objectively "non-standard" houses?
The answer in my mind is no less complex than it would be for software development: it depends, and you should be wary of anyone telling you that it's "obvious" that the answer is one or the other.
But there are modern carpenters that have hammers that are 100% metal and never break and actually improve your hammering power. The new electric hand planes work a lot faster, though you do have to be more careful because they can get out of hand quicker. etc etc.
In the end, they both build houses. The old-school carpenters might take longer, and they might have to know more techniques, but they get there in the end.
On the other hand, the modern carpenters sometimes go a littler overboard with their tools and have problems that old-school carpenters don't have, especially with their tools randomly stopping working in the middle of a job. It might not be often, but it happens.
To add to that, the old-school carpenters can actually use a lot of the new tools, too. They fit into the workflow and can be adapted to their old tools. It's just that they primarily stick with their old tools because they're used to them.
It's kind of interesting how much the world of woodworking and software development overlaps in that way.
Yes, it has quirks -- so does C, so does C#, so does JS, so does lua, so does tcl, so does every assembly language I've ever worked with.
So what? Are those preventing people from writing good code? Are those preventing people from shipping? Could it be improved? Has it already been improved? No, no, yes, and yes.
The biggest reason PHP's gotten so much scrutiny, to where people write these kinds of posts, is its ubiquity. When JS moved from being that simple, silly language built into the browser into a widely used one, we started seeing slide deck gags about the inscrutability of its comparison operators, yet JS seldom attracts this level of derision.
I don't believe the constraint would be the language itself, not with accellerators, opcode caches, JIT compilers, etc. I've always been told that PHP's performance is more down to the database than anything else.
I don't know where you pulled that number out of, but I just used an outdated version of `ab` to request the Hello World page of a fairly heavy PHP framework on a modest virtual server and got over 4k rps. Give me a proper server box and a well-written application, and I'll deliver the 25k rps that you want.
Besides, most webapps spend most of their execution time waiting for the database, memcached, redis, elasticsearch, or whatever. The speed of the language runtime makes very little difference.
Absolutely not, you could already go to 5k rps 10 years ago and PHP has massively improved since.
There will always be something negative regardless of what you pick, problem is to decide what your core values are when writing different types of software. If you don't, you are just comparing apples to oranges.
When it comes to PHP, core values are usually things that has to do with tooling, server architecture & deployment, not much the language (syntax, expressions, lambdas, classes etc) it self, except maybe it is easy to learn & use.
This means that developers who comes from a background of that the language itself is the most important part of a project will most of the time just get confused what PHP is about.
Java 32K
Javascript 30K
Python 23K
C 10K
C++ 10K
PHP 5K
Go 3K
Rust 500"A long-standing goal of the WordPress project is to be compatible with new versions of PHP on their release day. The next major version of PHP (version 8.0) is currently scheduled for release on November 26, 2020. WordPress Core contributors are working to ensure PHP 8.0 is supported in the next major version of WordPress (version 5.6), which is currently scheduled to be released on December 8, 2020."
https://make.wordpress.org/core/2020/10/06/call-for-testing-...
WordPress is the only web framework I've found that approaches stability of the Linux kernel.
Backwards compat is important and maintained.
Gutenberg hurt this a bit but it still does a great job of maintaining backwards compat.
I take old wordpress websites and update them and everything just works.
I take old laravel or code igniter or Drupal sites update them and everything just fucking falls over.
Fwiw, most modern WordPress development is JavaScript / React based. PHP is just a backend glue language at this point for things like templating.
The WordPress ecosystem, on the other hand, will probably make the switch much sooner.
But many things seem to be quite of a burden instead of a progress => why create a new match syntax when a switch is already well known for something similar? That will create confusion (thinking of all the for types of loops in JS!), plus it's still not an enum and cases will be missed.
And the worst being the attribute #[] syntax... why?! Almost every other language uses @attribute, and it is successful: simple to write, easy to read, why on earth a new and such complicated solution?
While php is making progress step by step, it has no chance of ever becoming of good reputation if it goes all the way to make itself more crazy.
Simple, it was already taken up [1]. Also `@attribute` syntax is by no way universal (and semantics wildly vary even with the same syntax): `#[]` in particular might have been inspired by Rust.
Also, the current use of @ is before a function call or some get, not before a method/class/... declaration, so a change in that direction would probably be possible. (plus the @ to suppress errors should probably be removed from the language anyway!)
Hah. Since the initial RFC was agreed, I think there were three changes to the syntax because no-one could agree. At one point it was going to be `@@attribute`. #[] is similar to or the same as Rust, I believe. It also has the advantage of being backwards compatible; while rarely used, comments in PHP can start with # instead of //, so older versions of PHP will just see an attribute as a comment. Of course, that also means that a comment in old code might now be interpreted as an attribute, but there you go.
Single @ is probably a no go because @ is already the error suppressing operator. Now, in my opinion that should be ejected from the language with extreme prejudice, but I doubt it ever will be.
I've used PHP professionally for over 20 years along with other languages. The decisioning of language design, at large, has been mired in "good enough and doesn't break backward compatibility" nonsense all over the spectrum. PHP was the poster child of thinking differently in the 90s. Make the languages BETTER by looking at others, not clutching your Perls /s. Arcane sigils are not the way forward, that's a known (eg Erlang, Haskell, Pony, Perl, etc), even with powerful features that put existing languages to shame.
From the docs it looks like it's possible in php7 and doesn't need explicit text mapping. But maybe I'm missing something?
There was a discussion on reddit about this exact same thing, shows that attributes lets you bind multiple events to the same listener more easily: https://www.reddit.com/r/PHP/comments/jgkp2r/php_8_before_an...
1) I love coding in PHP (I am a cs major)
2) I love riding scooters.
There - internet be damned !
2) I love riding scooters (I am a cs major)
FTFY
Sure, I'll look to Go, Ruby, Crystal, Elixir and others for more specialized stuff, but plain and simple CRUD web stuff is what PHP is made for.
C established a lot of common syntax, and there's some consensus for post-C syntax emerging, like `name: type` syntax, `match` expressions, non-nullable types and operators for them.
Nowadays `[1,2,3]` seems like an obvious syntax for array literals, but it wasn't obvious before JSON and other languages converging on it.
public static function new(): static
{
return new static();
}
It really brings the point across it's static.It's not an excuse for slacking on language design.
A bit better, due from 7.x backward it really doesn't transmit any sense to me. Just confusion. And I'm not alone. See https://www.reddit.com/r/PHP/comments/elrnp4/rfc_for_static_...
static a(int a[static 1]);> The second and third 'static' indicate late static binding, meaning they refer to the class being called, rather than the class defining this method.
Wait, so they're using "static" to mean the binding is happening later? Isn't that essentially less static than binding against the class being defined?
Python was less good and less bloated, but still bloated.
I think we use Python now only because our computers are orders of magnitude more powerful than a decade ago when I was watching Python Zope slow to a crawl and die.
But PHP is? I cannot imagine a "complex multi-layered system" for which PHP is a better solution than a Python stack.
$ php --version
PHP 7.3.11 (cli) (built: Jun 5 2020 23:50:40) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies
$ php -r 'echo "123" + 45;'
168
Contrast with Python: Python 3.8.3 (default, Jun 1 2020, 10:55:34)
>>> "123" + 45
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can only concatenate str (not "int") to strAlso what does "enterprise grade" mean? I'm not sure if you're aware but the forum we're talking on right now is written in PG's lisp dialect. I'm pretty sure arc is free.
JS is not a programming language, it's some nonsense.
You didn't have an answer for Guile though. I'd pay money to be able to build web apps in scheme instead of PHP.
What does this even mean, only lazy ass projects are started with Ruby? Yes Ruby is declining in popularity, as does PHP. It doesn't mean these languages are dying, there's just way more options to choose from these days.
For example what?
as someone only casually used to python im curious how so?
I worked with PHP 5.6 years ago and I hated it.
Recently I worked with PHP 7. Heard about all the work that's been done on it and I was kinda excited to try it. It's still so broken. It doesn't matter if they improve performance or add new cool features. PHP is broken in ways that can't be fixed without breaking compatibility. Fork it or put it out of its pain.
Of the top 10 websites in the world, PHP is partially or wholly powering more than half of them. Wikipedia, Wordpress, online retail.
I have personally created 6 figures of value because I could quickly dump some PHP scripts on a VPS server and start doing business.
My employer makes billions with PHP. It's not perfect, but it's rock solid for gigantic businesses.
Sure you can build yourself perfect shiny web services using modern bleeding edge languages, meanwhile businesses using PHP for decades are innovating and printing money daily.
I'm just calling it for what it is: a broken tool. I'm suggesting we let go of this broken tool and focus on tools that already work great, instead of wasting millions of human work hours on sub-par coding. Sure, you can still make billions with broken tools, but you could also have done that more easily with the right tools.
PHP is inherently stateless, making it easy to scale up. Facebook has had pretty close to a 100% availability rate since launch and PHP is still responsible for large swathes of their functionality.
Most people attacking PHP read a snarky article written in 2012 about PHP's limitations and cannot actually provide reasoning for why it's so awful.
Wikipedia, huge portions of online retail, forums and Facebook. Are these things inherently less secure or available than companies with a "modern" stack? Not really, in fact pretty much the opposite.
I'll let you in on a little secret: your customers could not care less about your shiny modern stack. As long as it's not preventing performance, security and new development then they don't care.
My PHP endpoints respond in <100ms, which to my customers is perceptionally instantaneous. They wouldn't benefit from any shiny modern language at all (but I do use them).
Thats what every Rust-Fanboy says about the C/C++ Ecosystem
They're actually great technologies, but for a very specific scope. Once you're outside of that strictly restricted scope, they're objectively horrible from an engineering point of view. The standard example is building a database with Excel + formulas.
There is a point in this whole thing. Some technologies should whither and disappear, slowly, over time, so that better one can take over. Or they should remain in their very narrow niches. For PHP I'd venture that it should remain a language for hobbyists creating personal home pages.
Related to this, standard, fixed column, steering wheels also were probably responsible for hundreds of billions of dollars of turnover globally.
But I'd still want my car to have a telescopic steering wheel, airbags, and all the modern safety features you find in a car.
The old school fixed column steering wheel should only be seen in museums or in classic cars out on the road with a special license.
And that was a project originally targeting PHP 4 and, by the time I was brought on, had made it all the way up to 5.x.
I mean, yeah, the code is garbage, but if he weren't allowed to write garbage code _he just wouldn't have written the code at all_. If that guy had to sit and learn proper paradigms and server administration and a bunch of other stuff, he would have just gone out and done something else instead.
Yeah, PHP lets you write shitty code (though it also lets you write _good_ code...). But in lowering the barrier to entry as it does, it also lets people who don't know how to write great code turn their ideas into reality. Unlike the suggestion of another comment, I've got a great deal of experience with "saner" languages, but despite PHP getting a bad rap because of its low barrier to entry I still admire PHP as a great equalizer.
So does Java, Python, C and C++. This is also a shallow argument. No language is perfect but PHP still suffer from the same design issues a 10/15 years ago, none of them have been correct and it's perfectly valid to point that out.
> My employer makes billions with PHP. It's not perfect, but it's rock solid for gigantic businesses.
And with C, since PHP is written in C and probably whatever fronts your PHP applications, and with Javascript because you sure ain't running PHP on the client and so on and so forth...
My advice is use the best tool for the job when possible, if you don't have a choice then learn to accept that most of us work with less cool languages/frameworks/projects ... the skill we bring is to find solutions for our customers and implement this solutions as best we can with the tools we have, most of the time a developer should be spending reading stuff(documentation,articles, code), thinking and the least time should be spent on typing code or tooling.
That's my story, I ignored PHP for years but since I had to work again on it recently and got pretty quickly hit by its "rough edges" I couldn't help but ask myself why such a bad language is still around.
PHP works (thought not perfect) lets me get things done.
PHP is good at what it does, but its usage is in decline over recent two decades, actually, if without wordpress's installation, its relevance might be very very limited if anything at all these days.
It made sense to use PHP EXACLTLY in the good bad old days because it was just leaner to bang out applications in PHP than with other languages.
Nowadays, I feel that PHP cake has been largely eaten by Python and Ruby.
Why using PHP with such a level of verbosity?
Conciseness is a valuable property which, for web development, PHP seems to have given up.
>Objectively, compared to other languages i've been working with it is more than OK. Despite it's lack of "style" it is easy to understand, host, tests, diagnose and it is powerfull for web applications. >I've been working on a SaaS API with Symfony now for 2 years, our metrics are good... >It is a good tool, it builds good softwares
Informed? These are opinions, dude. Where are the objective arguments? "It is ok, works for me" is not "being informed"
https://www.pixelstech.net/article/1334166417-PHP%3A-a-fract...