News for hackers. Stuff that matters.
Re:PHP is worth learning and using by brandon272 on Wednesday November 17, 2021 @10:05PM (#29261577)
I have used PHP for years. Like it. Have accomplished some nice things with it. Think it's evolved nicely in recent years. Feel it's a great tool for particular problems. Will continue to use it. Will always be open to alternatives.

Will never understand why some people find that so offensive and will tell you that you mustn't use it or imply that you are ignorant or stupid for using it.

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.
Re:PHP is worth learning and using by rp1 on Wednesday November 17, 2021 @11:16PM (#29261926)
I haven’t used PHP in over a decade. I can never forgot how much PHP got wrong in terms of how application development on the internet would happen. The ergonomics of using it were just… bad compared to other frameworks that came on the market. I remember when rails came out and it was so mind blowing compared to PHP. The language was certainly useful for a time, and I’m sure the language has progressed since, but switching to PHP still feels like it would be a huge step backwards.
Re:PHP is worth learning and using by Master_Odin on Thursday November 18, 2021 @04:54AM (#29263815)
Comparing Rails to PHP is unfair given that one is a framework and one is a programming language. Compare PHP and Ruby or Rails and Laravel to keep things apples to apples and oranges to oranges.
Re:PHP is worth learning and using by rp1 on Thursday November 18, 2021 @07:32AM (#29264690)
A lot of people 10+ years ago were building websites by interpreting PHP and using the output as HTML. The language (at the time) seemed to encourage this. I agree that PHP is not a framework, but it seemed to have some opinion on how HTML was to be generated, which most languages don’t have. Also rails is 7 years older than Laravel, so my point still stands that PHP was behind the curve.
Re:PHP is worth learning and using by jensensbutton on Thursday November 18, 2021 @09:06AM (#29265502)
If your standard is rails then literally everything in every language before rails was "behind the curve". Currently PHP has frameworks that have caught rails, but Ruby's perf is still garbage.
Re:PHP is worth learning and using by rp1 on Thursday November 18, 2021 @09:15AM (#29265587)
Django was released shortly after Rails. Ruby and Python developers _needed_ to build something like Rails and Django because those languages didn’t promote the same type of script-as-html pattern that PHP did. Had more thought gone in to serving websites, PHP might enjoy more popularity today. PHP had the first mover advantage after all, but frameworks built in other languages were purely better in almost all categories.
Re:PHP is worth learning and using by timeon on Thursday November 18, 2021 @01:36PM (#29268826)
10+ is not that long time ago. There was already Zend Framework. And for some basic API using framework may be overkill anyway.
Re:PHP is worth learning and using by motogpjimbo on Thursday November 18, 2021 @04:57AM (#29263833)
I'd be interested to know what you think PHP got wrong with respect to web development? The majority of the web is running on PHP to this day, so at least in terms of popularity it seems people don't feel this way generally. Furthermore, if one were philosophically-minded, it could be argued that PHP's "shared nothing/one thread per page" execution model is the very quintessence of HTTP.
Re:PHP is worth learning and using by kall on Thursday November 18, 2021 @08:14AM (#29265002)
It‘s also the essence of "serverless" so that model seems almost prescient.
Re:PHP is worth learning and using by pdimitar on Thursday November 18, 2021 @03:03PM (#29269745)
Except Erlang (and nowadays Elixir as well) has that for 30+ years already and it's done much better -- one green thread per request, and you can have 200,000+ of them at the same time on some fairly modest hosts, without any of them stealing run time from the others (as much as the hardware allows, of course).

PHP's "prescient" model demanded one OS process per request which is frankly absurd and I don't get how anyone views PHP in serious light because of this single fact alone.

Re:PHP is worth learning and using by codegeek on Thursday November 18, 2021 @03:51PM (#29270357)
Now think about how many companies/products need the power of Erlang vs PHP where PHP has more tooling, better ecosystem and far more available talent to choose from. Just because Erlang can perform better doesn't mean it is the right tool for the job. Performance is one aspect and PHP is good enough for lot of use cases while it has tons of other advantages that Erlang doesn't.
Re:PHP is worth learning and using by pdimitar on Thursday November 18, 2021 @04:11PM (#29270633)
Not performance per se. It's a much more robust model of work that in addition is sipping hardware resources more efficiently (so DoS attacks from one user to all others are hard).

"How many companies need X" is not a discussion, it's an exchange of opinions and won't ever go anywhere, so I refuse to start it.

I was merely responding to the claim that PHP had "prescient" ideas. It didn't.

Re:PHP is worth learning and using by rp1 on Thursday November 18, 2021 @11:03AM (#29266953)
I’m curious what metric you’re using to determine that a majority of the web is running on PHP.
Re:PHP is worth learning and using by paledot on Sunday November 21, 2021 @05:18PM (#29300322)
What alternative language do you propose? Not that asking for a source is unreasonable, but you seem to doubt that PHP has majority market share. Do you suppose that Node is more popular? Rails? Go? Flask?
Re:PHP is worth learning and using by motogpjimbo on Thursday November 18, 2021 @11:39AM (#29267403)
Surveys generally indicate that of sites where it is possible to determine the language, somewhere between 70% and 80% of them are running PHP. Of course, that figure will include a lot of WordPress sites.
Re:PHP is worth learning and using by rp1 on Thursday November 18, 2021 @11:44AM (#29267467)
What percentage of websites is it possible to determine the language? My guess is not many. Your metric self-selects for recognizing PHP sites because of Wordpress.
Re:PHP is worth learning and using by perttir on Thursday November 18, 2021 @04:03AM (#29263538)
Php has developed a lot in a decade.

Lots of new good things in php7/php8. The typecasting is way better than before, but it still allows you to be more "dynamic" if you want to.

Re:PHP is worth learning and using by toolslive on Thursday November 18, 2021 @06:04AM (#29264147)

   $x = [1,null,'xxxx', collect([])];
gettype($x) is "array". you can annotate a type as being an `array`. How does that help me exactly?
Re:PHP is worth learning and using by idoubtit on Thursday November 18, 2021 @06:37AM (#29264343)
Since $x is an array, it will get rejected at runtime by `function f(int $a)`. So this `array` type is limited but useful.

You can also add annotations like `/* @var []int */`. External tools (psalm, phpstan) use annotations in their static analysis of the code and will raise an error if $x elements are not integers.

Of course, it's far from Haskell, but my experience with types in PHP is smoother than in Python. Though it was 2 years ago in Python, and the environnement has probably matured.

In my opinion, a worse problem with PHP is that classes properties are dynamic. `class A {}; $a=new A; $a->x=1;` is perfectly valid and will add a property to the object that does not exist in the class. There's no simple way to forbid this, even at runtime (hacking the magic `__set()` creates other pain points).

Re:PHP is worth learning and using by monkey_monkey on Thursday November 18, 2021 @07:23AM (#29264617)
> In my opinion, a worse problem with PHP is that classes properties are dynamic.

There's a current RFC that is aiming to deprecate this 'feature'.

https://wiki.php.net/rfc/deprecate_dynamic_properties

Re:PHP is worth learning and using by echelon on Thursday November 18, 2021 @02:08AM (#29262858)
Here's a choose your own adventure for people new to the field. Pick something you want to build, then see which languages are the best suited. If you want to build several things, see which languages are the most recurring and versatile:

- Web frontend: Javascript/TypeScript

- Web backend: Javascript/TypeScript, Python

- Performant backend (where you manage threads and queues): Go, Java, Rust

- Machine learning: Python

- Command line scripting: Python

- Command line tools (binaries, eg 'ripgrep'): Rust, Go

- Mobile: Kotlin, Swift

- Systems/bare metal: Rust (discourage C/C++)

- Desktop games: C#, C++, GLSL, Rust (in ten years)

Mix and match.

The safest three to learn that give you the most flexibility are probably Javascript/TypeScript, Python, and Rust. You can build almost anything with those three.

Re:PHP is worth learning and using by herbst on Thursday November 18, 2021 @06:04AM (#29264145)
You can build almost anything with any language.

I've done shell scripts in PHP. Mobile development in Ruby, JS and haxe. Web development with Go. Nothing is stopping you, and if you know the language it is usually not to weird either.

Re:PHP is worth learning and using by pjmlp on Thursday November 18, 2021 @05:21AM (#29263947)
Rust is great, but if one is looking for a job in systems programming, C and C++ is what gets one hired, regardless of their flaws.

Recent example, while Android has adopted Rust for replacing their bluetooth stack, the newly introduced Android Games Development SDK focus on C and C++.

Or Microsoft, despite all their security speech, Azure Sphere OS and RTOS only support C on the official SDK, and the new WinUI components are all based on C++.

And naturally anyone wanting to contribute to the Rust compilers, most likely will need to brush up their C++ skills if they intend to mess with GCC or LLVM internals.

Re:PHP is worth learning and using by nicoburns on Thursday November 18, 2021 @05:47AM (#29264067)
> Rust is great, but if one is looking for a job in systems programming, C and C++ is what gets one hired, regardless of their flaws.

That's true, but as a beginner I feel like starting with Rust is a lot more accessible, and could help someone switch into C++ later.

Re:PHP is worth learning and using by pjmlp on Thursday November 18, 2021 @05:51AM (#29264092)
That I can fully agree on, after all it was learning systems programming via BASIC and Turbo Pascal, that made me adopt best practices in C and C++ from the get go.

So from that point of view, learning about lifetimes, modular code, and that bounds checking isn't evil are already good education stepping stones.

Re:PHP is worth learning and using by asddubs on Thursday November 18, 2021 @05:38AM (#29264029)
And even moreso for the embedded space
Re:PHP is worth learning and using by 3np on Thursday November 18, 2021 @08:56AM (#29265378)
I really would not discourage C, at all. Even encourage it, especially for embedded. It really makes you grok the lower levels in a way few other languages do, and it's still widely used.

C++, though, agreed.

Re:PHP is worth learning and using by BuckRogers on Thursday November 18, 2021 @03:26PM (#29270049)
I'll take anything on that list with static typing, and discard the rest. I've certainly enjoyed many of those languages but I wouldn't build anything with dynamically typed language unless I were forced to.
Re:PHP is worth learning and using by CyberFoxar on Thursday November 18, 2021 @03:53AM (#29263484)
You might also want to know a few languages were you're sure to get a job, and right now, it seems that Ruby on Rails and PHP are some really safe bets, compared to Python.

Sure, Rust is _fun_ but there's little demand for it right now in the market.

Re:PHP is worth learning and using by marcus_cemes on Thursday November 18, 2021 @06:47AM (#29264402)
Shoutout to Elixir/Phoenix for a (performant) backend.
Re:PHP is worth learning and using by cf100clunk on Thursday November 18, 2021 @04:17PM (#29270693)
This would ba a great Ask HN
Re:PHP is worth learning and using by klyrs on Wednesday November 17, 2021 @10:29PM (#29261687)
I haven't used PHP for years. I did some Python-based web stuff for a while. Python is a daily driver, but I still reach for PHP when I want to make something that responds to HTTP requests.
Re:PHP is worth learning and using by todd3834 on Thursday November 18, 2021 @02:04AM (#29262829)
I don’t find it offensive at all. I do, however, feel like the problems I worked on in many years of PHP were some of the least interesting projects of my career. It wasn’t the language’s fault necessarily but the types of things that language is most commonly used for? Also it was just a different time so PHP is possibly not the issue.
Re:PHP is worth learning and using by cityzen on Wednesday November 17, 2021 @10:20PM (#29261649)
and the best part is they're probably javascript developers that don't understand the hell they're living in.
Re:PHP is worth learning and using by todd3834 on Thursday November 18, 2021 @02:07AM (#29262849)
Pretty rare to find someone who writes a lot of PHP without also writing a lot of JavaScript. If there are JavaScript engineers who’ve never touched PHP then they probably don’t have much feelings about it at all
Re:PHP is worth learning and using by askonomm on Wednesday November 17, 2021 @10:37PM (#29261725)
So your response to the haters is to be a hater yourself? Why can't we just get along?
Re:PHP is worth learning and using by crate_barre on Wednesday November 17, 2021 @10:29PM (#29261684)
Now, why’d you have to get JavaScript involved? Can’t something else be a punching bag?
Re:PHP is worth learning and using by enchiridion on Thursday November 18, 2021 @01:22AM (#29262539)
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.

Re:PHP is worth learning and using by tasty_freeze on Thursday November 18, 2021 @02:35AM (#29263018)
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".

"Like it." etc Because this sentence doesn't have an explicit subject, it is implicitly the same one, "I".

As I recall, "wa" and "ga" were the Japanese particles which established new subjects. Say you wanted to talk about Bob's new car, you'd say something akin to "About Bob's new car, is expensive. Arrived last week. Has poor gas economy."

Re:PHP is worth learning and using by CrazyStat on Thursday November 18, 2021 @08:39AM (#29265204)
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 by hellojesus on Thursday November 18, 2021 @02:26PM (#29269333)
Interesting. The Chinese examples on the wiki page sounded completely natural to me and are in accordance with how I speak/interpret the language, but I never realized I was dropping pronouns due to their inference.

Thanks for the insight!

Re:PHP is worth learning and using by rat9988 on Thursday November 18, 2021 @01:38AM (#29262663)
> Any tips to write like that?

You notice the pattern. Mimic it. Struglle with it. Persevere.Endure. Will you reach perfection? Maybe not. No problem. Satisfaction is few layers below.

Re:PHP is worth learning and using by brandon272 on Thursday November 18, 2021 @09:58AM (#29266134)
I was just trying to get a number of key points across calmly and succinctly without wasting time diving into a long-winded academic debate about whether or not I am "allowed" to use a programming language that I have used with success for the last decade!

Not sure that I have any tips for you. Other than that it is often helpful to remove unnecessary words when communicating. This is something I have become sensitive to over the years. I used to write a lot more voluminously but I find it is harder to convey messages to people when they are confronted with a wall of text.