News for hackers. Stuff that matters.
Re:PHP is worth learning and using by smt88 on Thursday November 18, 2021 @12:05AM (#29262140)
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.

Re:PHP is worth learning and using by idoubtit on Thursday November 18, 2021 @06:16AM (#29264225)
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 the beginning of "index.php". And since the global scope was not limited to a file, tracing a variable through files and side effects was a nightmare. Even understanding the code intent was often hard!

Before PHP7, there were many elements of the language that were meant to simplify its usage, but had awful consequences in many cases. Even more because it bent the PHP community toward a quick and dirty process. "Magic quotes", the automatic escaping was one of those abominations. For any request input (e.g. POST form data), it added backslashes before single quotes. It was meant to protect data automatically in case it was inserted into a SQL request... It granted no security gain in this context, and was a mess for any other use.

Re:PHP is worth learning and using by tlackemann on Thursday November 18, 2021 @08:25AM (#29265089)
> 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 by 0des on Thursday November 18, 2021 @04:16PM (#29270692)
I've heard of JS referred to as "PHP with cooler shoes". I smirked.
Re:PHP is worth learning and using by smt88 on Thursday November 18, 2021 @11:32AM (#29267318)
As far as I know, you can't monkey-patch anything in PHP, but you can in JS[1]. That alone might make JS the more dangerous of the two languages.

1. https://www.audero.it/blog/2016/12/05/monkey-patching-javasc...

Re:PHP is worth learning and using by 3np on Thursday November 18, 2021 @08:45AM (#29265257)
Don't forget how <??> is built-in and was heavily abused to create insecure, incomprehensible spaghetti messes.

You'd have to try really hard to make callback labyrinths in JS match the mess that came out of the above combined with runtime-as-template-engine. This was basically idiomatic at the time.

Re:PHP is worth learning and using by znowcone on Thursday November 18, 2021 @01:38PM (#29268846)
I don't know man, cleaning up legacy PHP can be kinda fun, but when I work with some batshit insane piece of JS I feel like I'm going psychotic.
Re:PHP is worth learning and using by deergomoo on Thursday November 18, 2021 @06:18PM (#29271873)
Fun fact: to this day you still cannot have request parameters with “.” in them, because a dot is not valid in a variable name—even though register_globals was removed several major versions ago.

The value of a form input with the name “foo.bar” will instead be available under $_POST[“foo_bar”].

Re:PHP is worth learning and using by hnarn on Thursday November 18, 2021 @07:40AM (#29264739)
> So think of PHP less as a "bad language" and more of a code smell.

Surely that depends on when the PHP in question was originally written.

Re:PHP is worth learning and using by paledot on Sunday November 21, 2021 @05:15PM (#29300292)
Clearly you've never inherited anything written in Perl.