Hacker News new | past | comments | ask | show | jobs | submit login

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.




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 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.


> 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


I've heard of JS referred to as "PHP with cooler shoes". I smirked.


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...


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.


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.


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”].


> 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.


Clearly you've never inherited anything written in Perl.


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.


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.


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.


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.


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.


10+ is not that long time ago. There was already Zend Framework. And for some basic API using framework may be overkill anyway.


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.


It‘s also the essence of "serverless" so that model seems almost prescient.


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.


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.


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.


I’m curious what metric you’re using to determine that a majority of the web is running on PHP.


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?


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.


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.


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.


   $x = [1,null,'xxxx', collect([])];
gettype($x) is "array". you can annotate a type as being an `array`. How does that help me exactly?


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).


> 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


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.


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.


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.


> 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.


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.


And even moreso for the embedded space


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.


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.


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.


Shoutout to Elixir/Phoenix for a (performant) backend.


This would ba a great Ask HN


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.


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.


and the best part is they're probably javascript developers that don't understand the hell they're living in.


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


So your response to the haters is to be a hater yourself? Why can't we just get along?


Now, why’d you have to get JavaScript involved? Can’t something else be a punching bag?


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".

"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."


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


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!


> 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.


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.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: