Live data from Hacker News

PHP is worth learning and using

bulletproofphp.dev

331–340 of 468 posts

Re: PHP is worth learning and using

#331
post #61

Earlier quoted context omitted.

For people of a certain age and job history, the worst code they've ever inherited was written in PHP. I think JS can be worse. There are things that are possible with dynamic languages that are literally impossible with static ones. So think of PHP less as a "bad language" and more of a code smell.

I don't think any JS code can be worse than old PHP code. I've had to deal with legacy software written with PHP4. I was to port it to PHP7 since it was not compatible with PHP5.4+. The code used "register globals", meaning that variables were created on the fly from the parameters in the URL, the POST form data, and the cookies. Requesting `index.php?something=X` implied `$something = "X";` in the global scope at th…

> I don't think any JS code can be worse than old PHP code.

I'm currently working for a company where all our microservices were written in Node.js by juniors.

JS can absolutely be worse than PHP

Re: PHP is worth learning and using

#332

Hey if you don't like PHP please don't use it. I 'd hate to bring the culture of tiny packages, fake compilers, transpilers and weekly trends to PHP. Personally I use php because it works well and fast and still supports my 10 year old websites, not because it's cool.

Php change from 4.x to 5.x broke my web sites and I still don't trust php after that. I guess they might do it again from 7.x to 8.x, we'll see. If having the same code working for a long time is the most important for you then you should probably use java or .net. Maybe c++ also but that is not as popular for building web apps.

PHP are deprecating language "features" from 7.x to 7.y.

It's very hard for me to treat a language seriously when I could write code that simply won't be valid PHP in 2 years time, or worse, behaving differently.

Given the severity of some past PHP vulnerabilities, being on an old version can certainly be a problem.

> I guess they might do it again from 7.x to 8.x, we'll see.

PHP 8 has some _massive_ breaking changes

Re: PHP is worth learning and using

#333
post #287

Earlier quoted context omitted.

I see this as the opposite and find it adds quite a load of complexity and prevent to do some form of optimization in an app that has its own server. It adds its load of complexity on how to run the apps itself, you need an external server, apps often requiring some customization of the server that will run it (either mod-php or php-fpm). It means that parts of our app settings lives outside of the app, it also make…

I don't find this to be true at all. > you need an external server Spoiler, you need an external server for everything on the web; you've just been brainwashed to think serverless is actually that.

You do not need an _external_ server for a lot of languages. If you use node for example you can use the express package to run a custom server, or embedded tomcat for java

Re: PHP is worth learning and using

#334

Earlier quoted context omitted.

My favorite thing about PHP is the execution model. Every single request is brand new and runs the whole program start to finish. IMO that's extremely powerful in its simplicity and while you can get it in other languages, it feels like like a "core competency" for PHP (just like how async code is easier in javascript than in python, because JS kind of had it from day 1)

That's not quite a language feature though: one can write (Fast)CGI or similar programs in any common language.

I've never actually tried writing CGI scripts with a non-PHP language (I've not really seen the point since it's usually more ergonomic to just use a language native-server interface like Python's WSGI).

Do any other languages have the same kinds of optimisations that PHP has with FPM where it keeps the process alive but pretends it's a complete fresh execution at the language level? (getting the performance benefits of a persistent process, while having the simplicity of CGI-style execution).

Re: PHP is worth learning and using

#335

Hmmm... Most points in this article are shouting "yeah we have those too!!" but it didn't give any convincing arguments why I (or anybody who doesn't already know PHP) would like to learn and use PHP over other decent modern languages and ecosystems, which happen to have those points as well.

Frankly my reasons for using it boil down to:

1. WordPress uses it

2. PHP is far less terrible than I remember (having used it in very early days)

I manage a WP (woocommerce) site for a small business. It's not my day job, it needs to be simple. Most of the "day job" is handled by content management users. I have written a fair amount of plugins though to enable custom functionality and the process is perfectly fine.

I looked at Ruby, I looked at Python, I looked at node. There's nothing as simple and, frankly, as mature aside from commercial platforms like Shopify that charge an arm and leg.

Re: PHP is worth learning and using

#336
I'll be honest. I really don't like PHP. However when I was running a coding workshop, very frequently people would ask:

"How do I make a web page talk to a database?"

I'd say: Well, you know that HTML file? Rename it to become a PHP file and you're almost there!

As pretty much all cheap hosting already offers support for PHP (and MySQL for that matter) this would almost always work.

I would love to be able to do this with NodeJS, but imagine teaching that to an absolute beginner. The conversation would have to begin with hosting platforms / SSH / server management / reverse proxies etc....

Re: PHP is worth learning and using

#337

Earlier quoted context omitted.

I don't find this to be true at all. > you need an external server Spoiler, you need an external server for everything on the web; you've just been brainwashed to think serverless is actually that.

You do not need an _external_ server for a lot of languages. If you use node for example you can use the express package to run a custom server, or embedded tomcat for java

I suppose, but I've never encountered a production site that was using Gunicorn or similar as a true server. Usually that's coupled with something like Nginx or HAProxy.

So yeah, you technically don't need one for Ruby or Node.js, but I sure would.

Re: PHP is worth learning and using

#338
post #336

I'll be honest. I really don't like PHP. However when I was running a coding workshop, very frequently people would ask: "How do I make a web page talk to a database?" I'd say: Well, you know that HTML file? Rename it to become a PHP file and you're almost there! As pretty much all cheap hosting already offers support for PHP (and MySQL for that matter) this would almost always work. I would love to be able to do thi…

PHP: the original progressive enhancement.

Re: PHP is worth learning and using

#339

Earlier quoted context omitted.

You’re writing style is unique and grabbed my attention. Any tips to write like that? You didn’t use “I” at all, but it seems likely there are some other rules going on here.

No doubt there are people reading this message who speak Japanese who will correct me, but ... 30 years ago I studied Japanese a little bit. One interesting feature of the language was that once a subject was introduced, there was no need to restate the subject if it hadn't changed, resulting in paragraphs like the one which intrigued you. "I have used PHP for years." The first sentence establishes the subject is "I"…

This is called pronoun dropping [1] and happens in quite a few languages, including Japanese as noted.

I had a friend in college who would always point it out (in English, where it's not very common). I still notice it often years later and I'm pretty sure it's thanks to her making me aware of it.

[1] https://en.wikipedia.org/wiki/Pro-drop_language

Re: PHP is worth learning and using

#340
post #280

Earlier quoted context omitted.

(naieve fibonacci) like this: just did some measurements on my laptop: | Language | n | time(s) | |----------------------+----+---------| | php (7.4.25) | 42 | 422.0 | | python3 | 42 | 90.0 | | haskell (ghc -O3) | 42 | 13.8 | | f# | 42 | 5.6 | | ts | 42 | 2.8 | | ocaml (ocamlopt -O3) | 42 | 0.98 | | C (gcc -O3) | 42 | 0.66 | (edit: added php version in table. )

This is what I get locally: time php fib.php 42 23s time python3 fib.py 42 1m1s I suspect that you're doing something very wrong, like running PHP with an active debugger or similar. If we're talking in comparison to slow interpreted languages like Python, then function calls in PHP are not particularly expensive. Debuggers can make them quite expensive though. Edit: Just to note, PHP's execution time drops to 4s wit…

I also get around 23s, PHP 7.4.5
Post reply on HN