Live data from Hacker News

A look at modern PHP

lwn.net

261–270 of 610 posts

Re: A look at modern PHP

#261
I've been programming in PHP since 2007 and I absolutely love it. I've long ignored the hate for it here. I worked hard and followed best practices to get good at PHP.

In 2015, I started writing "projectionist" software in PHP to completely automate my home theatre.

I was a projectionist at three different theatres for about half a decade. I spoke with old-timers to really get it right and have been tweaking this script regularly ever since.

I've got a Netflix-style website for my movie collection. I can watch a feature either in my browser or choose to play it in the cinema. I can even schedule a feature for 7:00pm and it will wake-up 30 minutes before with music and nice lighting, assemble all the dancing hot dog ads and trailers, play it, turn the lights on for the credits, and shut itself down 30 minutes after.

The little ODROID running the whole theatre opens a chat room connection over XMPP with my servers so it can respond to controls in the app, whether I'm adjusting lighting or sound levels, putting it in Desktop mode, or manually controlling the curtain and projector.

I just ignore the PHP hate because I find it extremely powerful- it can do everything I could ever need. I also always want to keep an open mind.

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

Re: A look at modern PHP

#262

I wonder if most developers that trash on PHP for trivial issues like seen in this thread haven't been using it for many years, or had a bad experience (e.g. maintaining a legacy app). Some developers live in a kind of technical vacuum where, I guess they assume, the technical features of their programming language are what makes the difference in the value of the business they're building. In reality, the difference…

I'm a PHP "hater", so take this for what it's worth.

You are very close to implying that the language doesn't matter if you can hire developers and there are a lot of good packages in the ecosystem.

Having worked on several PHP projects (Most being version 7.0+ and zero of them being older than 5.3), the languages is STILL full of gotchas, and it's a huge drag on productivity. I assert that this DOES matter. Even basic stuff like trying to use the default "array" as a dictionary has absolutely ridiculous issues like if you try to use a string as a key, but it is a string of digits. It will automagically convert your string to an int and totally F-up your dictionary.

I've actually been bitten by that one. And it showed up in production, because I didn't know or care what the string keys might be. Who the hell would've guessed that behavior after working with non-broken languages before?

Inb4 "That just means you're dumb. Just use SPL. You can write bad code in any language."

I've used Symfony. It's good. I haven't used Laravel. I assume it's also good. I still don't know why you'd choose to start a project in PHP today when there are great libraries in many other languages that are not as broken as PHP.

Honestly, PHP 7+ is not horrible, but it's also not better than anything else... In fact, the very best PHP code you can write today looks basically the same as the best Java code you could've written a decade ago.

Re: A look at modern PHP

#263
post #168

It saddens me to see some of the (largely baseless and otherwise largely historical) hate for PHP. I use Hack in my day job, which has at this point diverged from PHP, and I like it for the most part. The thing that PHP does right that so few languages do is having a stateless core in the webserver. This is an incredibly efficient approach to serving HTTP traffic. Consider the startup cost issues with Java, or Rails'…

Request processing in Java (or any other sane language) is Request-scoped.

The Request is a variable, the Response is a variable, they're only in local scope?

And any data the developer uses will also be local -- and thus stateless -- unless they go out of their way to share something. (Caches are a common example, but harder in PHP since nothing by default is shareable.)

You don't need to deal with threads if you're seeking PHP-equivalent functionality.

And if you did need to deal with threads, I find your claims about overheads & difficulty hard to read without a little skepticism. An idle thread is faster to start than spawning a process, an uncontended synchronization takes only 20-250 CPU cycles (ie. a modest number of nanoseconds), and a thread pool can be sensibly managed in 2-3 lines of code.

Re: A look at modern PHP

#264

Earlier quoted context omitted.

Some people simply have reasonable standards. I tried for years to hire a PHP dev. I never found a single one. I found tons of people who had PHP on their resume, and not a single one of them was anything close to competent. PHP only makes hiring easy if you don't care about the quality of work that gets done. I can hire a million PHP monkeys, but everyone who has the right combination of intelligence and conscientio…

You can hire "good programmers" and ask them to write PHP - Facebook does

Facebook, Slack, Etsy, the list goes on. In fact, I think all thosr companies are actually hiring right now, unlike many of those advanced non-PHP shops.

Re: A look at modern PHP

#265

I wonder if most developers that trash on PHP for trivial issues like seen in this thread haven't been using it for many years, or had a bad experience (e.g. maintaining a legacy app). Some developers live in a kind of technical vacuum where, I guess they assume, the technical features of their programming language are what makes the difference in the value of the business they're building. In reality, the difference…

Coming from Java, the one pet peeve I have is the automatic type conversion. I just find that I never really know what my variables are _really_ holding.

It's one of those foundational issues that I just can't get over.

...but it's my personal problem - I don't hate PHP.

Re: A look at modern PHP

#266

Earlier quoted context omitted.

> This is absolutely not the case, and you know it. Almost every language has a wealth of HTTP tools and frameworks, and many of them come built-in. Lots of languages have HTTP tools and frameworks, but not many of them are even comparable in scope to Symfony or Laravel. Out of curiosity, can anyone point me at some frameworks in other languages that have the following things built-in? * Route matching and dispatch *…

Spring Boot has most of the important parts of this. And super easy to call a library for anything else, or write 10-20 lines of code yourself. This is all in a performant, reliable and secure compiled language (Java). Language improvements and modern frameworks have also addressed the long-winded code which used to be an issue.

> Language improvements

A.k.a., Kotlin. :p

In all seriousness, though. The only thing PHP still has over Java is that when I say my function takes Foo type, you can't give it null instead.

Re: A look at modern PHP

#267
post #14

Even with PHP7, PHP still feels like it is playing catch up. There is nothing new or revolutionary in PHP7, just adopting features present in other major languages. Adopting as other newer languages like Go and Rust seems to be moving beyond those features. A catch up into a world that's on its way out, if one will feel so blunt. PHP's raison d'être remains its ease of getting an instance running on a webserver. But…

Not only is PHP playing catch-up. It's only playing catch-up to Java. That's... not the highest bar, IMO.

Re: A look at modern PHP

#268
post #168

It saddens me to see some of the (largely baseless and otherwise largely historical) hate for PHP. I use Hack in my day job, which has at this point diverged from PHP, and I like it for the most part. The thing that PHP does right that so few languages do is having a stateless core in the webserver. This is an incredibly efficient approach to serving HTTP traffic. Consider the startup cost issues with Java, or Rails'…

Request processing in Java (or any other sane language) is Request-scoped. The Request is a variable, the Response is a variable, they're only in local scope? And any data the developer uses will also be local -- and thus stateless -- unless they go out of their way to share something. (Caches are a common example, but harder in PHP since nothing by default is shareable.) You don't need to deal with threads if you're…

I think what the comment really means by "request scoped" is that the PHP process is totally torn down after each request. In Java you can mutate global state as its running. You can leak memory until you OOM.

Re: A look at modern PHP

#269

PHP, Python and Ruby all feel to me like last-generation languages. IMO we should be building new frameworks on modern languages that support concurrency & static typing. The most promising new stack I've seen is Kotlin's KTOR framework. Thanks to the expressiveness of Kotlin it's not really any more verbose than something like PHP or Ruby but it's far more powerful and robust.

One of the main benefits of PHP for web serving, is the "shared nothing" architecture. By operating as a non-threaded application, entire categories of bugs and security holes are avoided. Are there situations where threads could genuinely help? Sure, there is always an exception to any rule, but for the vast majority of projects where PHP is used, I don't believe threading would achieve much in terms of performance…

Yeah, but if you're worried about bugs and security holes, I'm not sure PHP can possibly help more than it hurts. E.g., type juggling: https://www.netsparker.com/blog/web-security/php-type-juggli...

Re: A look at modern PHP

#270

Earlier quoted context omitted.

I think the logic is that those served by PHP are better served by platforms. Those with advanced needs are going to use a different language. PHP isn't being replaced so much by Python, Go, and Rust as it is being replaced by Medium, Wix, and Squarespace.

As someone who works with PHP reasonably often, I'd say you have a very limited view of what PHP is actually used for in 2020, if you think 3 hosted blog services will replace it.

The majority of PHP usages tend to be, frankly, unsophisticated Wordpress, WooCommerce, Magento, and Drupal sites that are hacked up to support e-commerce. These needs can now be met by a vast array of ecom and omnichannel platforms.

This is the direction things are trending.

Post reply on HN