Live data from Hacker News

A look at modern PHP

lwn.net

441–450 of 610 posts

Re: A look at modern PHP

#441
post #424

Earlier quoted context omitted.

I'm in a similar boat. I've decided that whatever it is that makes PHP successful must be exactly the same thing that has made JavaScript successful. It's going to sound extremely condescending, but here it is, anyway: I believe that the majority of people who defend PHP (and JavaScript) are people who have ever only written code in Java (especially <=1.6), JavaScript, and PHP. Maybe C for fun or in college. In light…

As someone who's worked heavily in C++/Java and tends toward functional programming approaches I enjoy PHP. There are some features in the language you should avoid, variable-variables being one of the ones that makes logic very difficult to decipher - but C, C++ and Java all have those - and Javascript has the wonderful combination of substr & substring. The useful portions of PHP are extremely powerful, having acce…

Going a bit off-topic, but I can't imagine doing "functional" programming in PHP or Java. C++ has const and top-level functions (PHP kind of does, but the autoloader...). It has (real) generics. It has move semantics, which is great for functional pipelines.

Re: A look at modern PHP

#442

Earlier quoted context omitted.

It takes 5 seconds on Google to find a myriad complaints about weird, unexpected, and downright incorrect things that PHP does. That wasn't the point of my reply. The point was that language choice CAN affect productivity. And having a bunch of gotchas is something that will negatively affect productivity. I simply gave the first example that popped into my head that actually tripped me up.

Unit tests would have caught this, if you wrote them.

My unit tests did not cover all possible strings, unfortunately.

Re: A look at modern PHP

#443

Earlier quoted context omitted.

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.

Tbh, that's done in modern PHP frameworks as well. ReactPHP & Co rely on you not using global variables, Symfony's architecture is built for that as well. You don't want to incur the startup cost for every request, because it's very slow.

This doesn't matter a lot in single requests of course, but once you're writing APIs that get considerable traffic, you'll want to cut out those 50ms and the load.

Re: A look at modern PHP

#444
post #39
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…

> PHP's raison d'être remains its ease of getting an instance running on a webserver. But with fewer people self-hosting these days, that has become less an advantage. And even for those who do self-host, the advantage is becoming narrower as other languages have made it easier to distribute their web applications. And if you are doing something moderately complex/serious/modern you probably need/want composer anyway…

I think that's kind of part of the point though -- PHP provides a gentle slope from "single HTML file" to "big project".

You can start with a plain HTML page and go "Hey, I want to do X" and just throw some code in the middle of the page. When you decide you need a database, MySQL is right there and easy to use. When you decide you need some libraries, you can just download and `include()` them. All of this can just be FTP'd up to some server somewhere.

As this grows bigger, there are tools like composer and frameworks/libraries like Laravel and Symfony. You can still FTP those, but once that gets painful you can start to learn the bit of *nix skills it takes to start managing this different ways.

At no point have you had to worry about nginx/apache/supervisor/anything else. But whenever you're ready, that's all there too.

This is basically the path at least one guy I know took to going from working in a totally non-technical industry to building a massive (almost 2 million lines at this point) application that allowed people in the industry to stop working with a bunch of exploitative big name companies and instead self-manage and earn more money. And now that product makes a bunch of money for him.

And then there's the scales that places like Twitter/Facebook/etc took it.

I think the big thing that always gets missed here is PHP's... egalitarian nature. Yes, at some point it just ends up a in some ways less-good version of other things. But it provides an incredible opportunity for people who aren't engineers to realize their ideas without immediately becoming overwhelmed with needing to learn a huge amount of foundational knowledge before they can lay down their first line of useful code, and seeing that through to crazy places.

Re: A look at modern PHP

#445

Funny, while I see that many people enjoy the features that come with this maturity (and I am happy for those people of course), I long for the simplicity of the classic style PHP. Personally, I do not enjoy the Java-style 'enterprisey' direction of PHP. I don't like types, anonymous functions, treats and all the other fancy stuff. To be honest, I think I myself would still be happy with PHP4. I use thin scripts, alm…

I do like the enterprisey direction personally, mostly because it works so well with a good IDE. I'm using PHPStorm and once you've got your project set up, code completion/suggestion and inspections are something I love.

Re: A look at modern PHP

#446

Earlier quoted context omitted.

I'm in a similar boat. I've decided that whatever it is that makes PHP successful must be exactly the same thing that has made JavaScript successful. It's going to sound extremely condescending, but here it is, anyway: I believe that the majority of people who defend PHP (and JavaScript) are people who have ever only written code in Java (especially <=1.6), JavaScript, and PHP. Maybe C for fun or in college. In light…

Maybe, in my case since I am currently in the non-PHP phase of my alternating PHP/non-PHP job history. PHP has been less than 50% of what I've done (the rest being far more on-trend, if you will) though disproportionately represented among successful and profitable projects. The only-ever-PHP coders I have known tend to be fairly polarized between fear of the unknown and the "grass is greener" attitude. The ease of e…

With other languages there's some hope of a free lunch and it engages our tendency to optimism.

Asking as someone who's mostly only written PHP (and some javascript, more recently): can you expand on this? What kind of "hope of a free lunch" is there with other languages?

Re: A look at modern PHP

#447
post #17

I've been using PHP for over 15 years and always liked it. There is no other webserver language that's so easy to use and so deployable while still being fast. But for larger projects the available frameworks are just okayish. I think Symfony is closest to what a good framework should be. But every time I use it I wish it would be like .NET Today .NET core is also available on Linux and very easy to deploy so I don't…

As someone with 0 experience in .NET, I'd love to hear what's so cool about it.

Tooling, tooling, tooling!

.net has proper debugging working compared to node.js, has great standard library, can develop 3d games, servers, mobile apps, web apps, machine learning ,desktop apps and even (some) embedded devices.

Great instrumentation and support with quality updates from MS and the community. The IDE is superb and free (community edition at least), drag & drop desktop & mobile app development (if you wish).

I've worked with PHP for about 4 years (5.x - 7.0 days), .net for the next 6 years and node.js for the last 1 year, and every day i work with node.js i wish i could switch everything to .net because it's sooo much better & smoother experience, and everything just works together so well.

Re: A look at modern PHP

#448

Earlier quoted context omitted.

My guess is that the numeric indexing thing happens a lot but it's definitely rare for it to cause a visible problem and even rarer to be identified as the cause since it is unexpected. I've been bitten by it and also stuff like 800=="8E2". I've never been able to make an adequate defense of PHP, yet also have never seen another language match its success rate of getting useful software into the hands of users. I hav…

I'm in a similar boat. I've decided that whatever it is that makes PHP successful must be exactly the same thing that has made JavaScript successful. It's going to sound extremely condescending, but here it is, anyway: I believe that the majority of people who defend PHP (and JavaScript) are people who have ever only written code in Java (especially <=1.6), JavaScript, and PHP. Maybe C for fun or in college. In light…

Yes, that did sound condescending. I'm both a defender and detractor of JavaScript. I'm mostly a detractor of PHP, but could possibly defend it once in a while if I see misinformation.

Peter Norvig at some point came to the realization that the deficiencies of Python relative to Lisp were not deal-breakers, and I don't think that stemmed from his limited experience.

Re: A look at modern PHP

#449
post #271
post #152

Earlier quoted context omitted.

> Would I use PHP if I was starting out today? Unlikely, but I know PHP inside out and can wield it to my wicked ends with ease so won't be dropping it anytime soon. So just out of curiosity, if you hypothetically did start learning web development today from scratch, what would you spend time learning instead of PHP?

When I started I struggled with browser inconsistencies. Over the years Javascript has come a long way and whilst I'm not 100% sold on node.js, I like the idea of using the same language across front and backend so likely would have gone down that road.

If after 20 years of PHP experience you arrived at "not 100% sold on node.js" as your most likely alternative, that to me more than anything else signals a strong, ongoing vote for PHP :)

Re: A look at modern PHP

#450

Earlier quoted context omitted.

Can you attribute that specifically to PHP making that possible? Why couldn't an equivalently capable peer use Python to do the same?

PHP has excellent development experience. After updating your code, you can just reload the page. That's it. It's seamless. This is something that I sorely miss now that I'm a .NET developer. Also, the PHP ecosystem is friendly to beginners. Compare these authentication docs for a PHP project vs a .NET project: Laravel (PHP): https://laravel.com/docs/7.x/authentication ASP.NET Core (.NET): https://docs.microsoft.com/…

> After updating your code, you can just reload the page. That's it. It's seamless.

This is available with many other languages as well, i.e. https://github.com/cosmtrek/air

It may require an external tool, but the deployment experience is a lot simpler for Go than PHP.

Post reply on HN