Live data from Hacker News

PHP is worth learning and using

bulletproofphp.dev

251–260 of 468 posts

Re: PHP is worth learning and using

#251

| php is fast. https://benchmarksgame-team.pages.debian.net/benchmarksgame/... it's faster than python, but my grandma is too and she died in 1993. However, function calls are extremely slow. If you would bench something like a naieve fibonacci implementation (or ackermann's function) you would be surprised.

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

Re: PHP is worth learning and using

#252
post #246

Earlier quoted context omitted.

I love maintaining old rails projects. No worries with that, MVC is making it easy to work with any project done by someone who knows the language. The language allows and encourages updating as well. It can be fun even. PHP had no common way to do anything for a long time and you still see it from people writing PHP today.

My point was more that if there's money being made with some chunk of code, a sensible product owner would allow a modern refactor or even a rewrite in the same language to not endanger the long term success of said app.

I see. Well personally I never witnessed such a product owner. My whole carrier with PHP legacy code evolved around 'never touch a running system'

But I like the idea that these people may exist out there :)

Re: PHP is worth learning and using

#253

Earlier quoted context omitted.

You asked > So tell me again, why should I use PHP? How will it truly help me? What does it do better than everyone else? I gave some reasons, citing problem domains for which there are stable, supported solutions in PHP. e.g. payment gateways, email handling, and citing the availability of programmers who can support medium bespoke or tailored systems. This isn't an "appeal to statistics" it's a strength about the e…

None of what you enumerate is game-breaking, at least in a chunk of the programming area. You seem to be referring to an area where people pay pennies + have almost zero programming experience so they want to launch a project with clicks. Sure. In that area PHP still more or less dominates. But I thought we were discussing the actual programming? > I thought you were asking a question. That's exactly why I said what…

> You seem to be referring to an area where people pay pennies + have almost zero programming experience so they want to launch a project with clicks.

Over my career, I've worked with companies using PHP in sales. One of those had over a million customer subscriptions, the other was a multi-national looking at PHP for a greenfield e-commerce project. I noticed working in Europe some high-growth agencies that use PHP.

> So tell me again, why should I use PHP? How will it truly help me? What does it do better than everyone else?

> But I thought we were discussing the actual programming?

Your original question just said "use PHP". PHP is a general purpose web scripting language. It's similar to Python or Ruby. It is generally more performant and later versions have a gradual type system. It's traditionally run as a shared-nothing single-threaded script, which makes it easy to reason about, and in real life has proved to be a stable way to run things in production, as it avoid bugs that can arise around stale state, multi-threading and it keeps running if other libraries have bugs that leak memory.

Later versions have introduced a JIT and support for concurrency concepts such as fibres, as in the upcoming PHP 8.1 https://php.watch/versions/8.1/fibers.

Arguably, the thing that would make you use it over Python, or Ruby, is the ecosystem, especially around content management and e-commerce, as the language itself is roughly comparable to others. Also I think there are more agencies that support PHP, rather than Python or Ruby.

Re: PHP is worth learning and using

#254

| php is fast. https://benchmarksgame-team.pages.debian.net/benchmarksgame/... it's faster than python, but my grandma is too and she died in 1993. However, function calls are extremely slow. If you would bench something like a naieve fibonacci implementation (or ackermann's function) you would be surprised.

Is that still true when using PHP 8.0 with JIT enabled?

https://twitter.com/ArkadiuszKondas/status/11196548025800212...

Re: PHP is worth learning and using

#255

| php is fast. https://benchmarksgame-team.pages.debian.net/benchmarksgame/... it's faster than python, but my grandma is too and she died in 1993. However, function calls are extremely slow. If you would bench something like a naieve fibonacci implementation (or ackermann's function) you would be surprised.

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

Is JIT enabled and configured for PHP?

Re: PHP is worth learning and using

#256
post #83
post #77

Earlier quoted context omitted.

How so? Ruby just released a new version with a JIT and new concurrency model. Rails is releasing a new major version later this year with a bunch of great improvements. Shopify, Stripe and others are putting a ton of improvements into the Ruby interpreter. Many large tech companies still use it. Many startups still use it. If nothing else, it's still a popular scripting language. It's not as 'trendy' as it once was,…

> How so? Ruby just released a new version with a JIT and new concurrency model. Rails is releasing a new major version later this year with a bunch of great improvements. Shopify, Stripe and others are putting a ton of improvements into the Ruby interpreter. Do all of these make it faster than PHP?

> Do all of these make it faster than PHP?

We'll need to look at it a year or two from now and compare oranges to oranges; the new Ruby JIT (YJIT) is optimized for real world web apps, not for some artificial fibonacci benchmark. Shopify is using benchmarks on actual Rails apps like their store front to see the improvement (https://speed.yjit.org/). If I had to bet I think yes Shopify is serious enough about this to make Ruby faster than PHP - who is working on PHP internals now - Zend? In the end it's mostly a question of how much resources you throw at a problem.

Re: PHP is worth learning and using

#257

Earlier quoted context omitted.

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

Re: PHP is worth learning and using

#259

Earlier quoted context omitted.

None of what you enumerate is game-breaking, at least in a chunk of the programming area. You seem to be referring to an area where people pay pennies + have almost zero programming experience so they want to launch a project with clicks. Sure. In that area PHP still more or less dominates. But I thought we were discussing the actual programming? > I thought you were asking a question. That's exactly why I said what…

> You seem to be referring to an area where people pay pennies + have almost zero programming experience so they want to launch a project with clicks. Over my career, I've worked with companies using PHP in sales. One of those had over a million customer subscriptions, the other was a multi-national looking at PHP for a greenfield e-commerce project. I noticed working in Europe some high-growth agencies that use PHP.…

> It's traditionally run as a shared-nothing single-threaded script, which makes it easy to reason about, and in real life has proved to be a stable way to run things in production.

I think we have a vastly differing definition of "in production". I'll agree PHP was good enough for plenty of things, and likely still is. But good enough in general to run things in production as it's understood today? You'll find that many people will disagree with you here, not just me.

> Later versions have introduced a JIT and support for concurrency concepts such as fibres, as in the upcoming PHP 8.1 https://php.watch/versions/8.1/fibers.

That's what I mean, not only for PHP but for like 99% of all programming languages: they play catch-up, waaaaaaaaay too slowly and gradually, with things that should be baseline by now. Happily Erlang/Elixir are having lightweight and transparent parallelism and concurrency for a long time now. Languages like Go and Rust also progressed very well in this area so I am looking to work more with them in the future as well.

---

I think you and I are not aligned on what is "successful" or "good enough". You seem to insist that statistical success speaks something of the merits of a technology, and this is where I and many others disagree: people just adapt to what's given to them. That doesn't say almost anything about if the thing is good or not. People simply get what they can. Back then PHP was available so they took that. The rest is post-hoc rationalization. Stretching the simple and isolated historical fact "people used PHP because there was nothing else viable at the time" to mean that "PHP is good and successful" is where I'll disagree with you.

But yep, we severely digressed from the original discussion. I am OK with that though.

Re: PHP is worth learning and using

#260

Earlier quoted context omitted.

That ship has sailed a long time ago (or you're just playing around and most languages will have a REPL nowadays) Modern PHP wears a business suit and wants to buddy the "big boys" (Java/C#) of the world. You'll have deployment pipelines, strong push towards classic OOP, strict type checking etc. I personally think ruby for instance is leaner in its dev process in most real world projects.

OP is correct, you still can develop like this with PHP, and no the ship has not sailed for many. You can have deployment pipelines etc, but if you like, you can still develop the ancient way - it still works.

apt-get install libapache2-mod-python

Now you can put .py files into your www folder, like .php files.

Post reply on HN