Live data from Hacker News

PHP is worth learning and using

bulletproofphp.dev

281–290 of 468 posts

Re: PHP is worth learning and using

#281

Earlier quoted context omitted.

I used to believe this, but... But that's just not true. All the things you mentioned are a yum/apt/nix/pacman/ install away on Linux, and probably as simple to install on macOS. I'm sure Windows has installers for these, too. So, it's no harder to develop in them than it is in PHP. You could argue it's cheaper because you don't have to pay for a shared hosting provider to host your files. However that's a bit moot s…

I went on a rant, but didn't mean to. I don't have anything against PHP, it's got a valuable and relevant place on the the web. It's important to many people, and like you said you find it fun, which I think is important for our productivity as devs. However, I think this recurring misconceptions how easy PHP is to develop in needs to stop. PHP comes with a lot of complexities. Worst kind of complexity to learn: hidd…

One person’s complexity is another person’s valuable job skill. PHP and Apache aren’t hard to setup and configure if you know how it works.

Re: PHP is worth learning and using

#282

Earlier quoted context omitted.

I like PHP and still use it today. But never in my life heard PHP is cool. Am I missing something?

Well, early 2000s it was definitely cool. Using ASP and want to calculate an MD5? Oh, you need to pay an add-on for that. Want to send an email? Ditto. Then there was PHP, with all included (and cheaper hosting, because Linux). I started working on a web shop and after a month ASP was legacy and PHP the new cool thing, together with MySQL instead of using... Access as "database" in ASP.

I was new to the world of software development in 2000 (in high school) but immediately loved PHP / MySQL. Made it easier for me to stand up websites for my two bands and integrate more dynamic and database-oriented features into those sites. And hand-wrote JS for things that at the time seemed cool (silly in retrospect hover effects).

It was the SQL part of the book that helped me build the SQL skillset that is an integral part of my day job.

Used a book similar to this one:

https://www.thriftbooks.com/w/professional-php4-programming_...

Re: PHP is worth learning and using

#284

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.

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)

Forgive me for going a little off topic here but is it really true that JS was async-friendly from day 1? When I started using JS seriously 8 years ago, async code was horrible (callback hell, etc.) The web standards guys retrofitted native async way after the matter.

Re: PHP is worth learning and using

#285
post #163

Most arguments against PHP miss the point. You know why you should use PHP? Because it's fun and you can get something running much quicker than figuring out the Elixir, Ruby, Rust, whatever ecosystem and paradigm. Maybe PHP is not so good at WebSockets or async worker threads, but most projects don't need that. There's no shame in doing long polling, users can't tell the difference anyway! PHP shines when you're try…

I used to believe this, but... But that's just not true. All the things you mentioned are a yum/apt/nix/pacman/ install away on Linux, and probably as simple to install on macOS. I'm sure Windows has installers for these, too. So, it's no harder to develop in them than it is in PHP. You could argue it's cheaper because you don't have to pay for a shared hosting provider to host your files. However that's a bit moot s…

If you don’t manage your own servers I don’t think you can call yourself a professional developer. “My hosting provider doesn’t let me do X” is a lame excuse with cloud servers in the $10/mo range.

I do a lot of work with PHP, both legacy and new code. The number one mistake I see with PHP sites set up by amateurs or cheap hosting services is running Apache+PHP on the same server as MySQL or Postgres. Separate those and performance and stability problems go away. That’s because relational databases consume as much memory as they can get, not because PHP is inherently slow or unstable.

Re: PHP is worth learning and using

#286

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

How is php 422 seconds? Are you basing that off the return value of the function? FWIW, I get 57 seconds when I run your function with PHP 7.4 using microtime().

Re: PHP is worth learning and using

#287

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.

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)

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 updating php itself quite annoying.

Re: PHP is worth learning and using

#288

Earlier quoted context omitted.

$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. Tho…

> 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

#289

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

Was curious. The same implementation as /u/toolslive:

  PHP 8.0.12:
  
  $ time php fib.php 42
  42 433494437
  
  real 0m29.274s
  user 0m29.003s
  sys 0m0.105s

  $ time php -dopcache.enable_cli=1 fib.php 42
  42 433494437

  real 0m26.341s
  user 0m26.179s
  sys 0m0.058s
  ----------------------------------------
  PHP 7.3.5:
  $ time php fib.php 42
  42 433494437

  real 10m23.573s
  user 10m16.592s
  sys 0m1.828s
  ----------------------------------------
  Settings for PHP 8:
  PHP Version => 8.0.12
  auto_globals_jit => On => On
  pcre.jit => 1 => 1
  opcache.jit => tracing => tracing
  opcache.jit_bisect_limit => 0 => 0
  opcache.jit_blacklist_root_trace => 16 => 16
  opcache.jit_blacklist_side_trace => 8 => 8
  opcache.jit_buffer_size => 0 => 0
  opcache.jit_debug => 0 => 0
  opcache.jit_hot_func => 127 => 127
  opcache.jit_hot_loop => 64 => 64
  opcache.jit_hot_return => 8 => 8
  opcache.jit_hot_side_exit => 8 => 8
  opcache.jit_max_exit_counters => 8192 => 8192
  opcache.jit_max_loop_unrolls => 8 => 8
  opcache.jit_max_polymorphic_calls => 2 => 2
  opcache.jit_max_recursive_calls => 2 => 2
  opcache.jit_max_recursive_returns => 2 => 2
  opcache.jit_max_root_traces => 1024 => 1024
  opcache.jit_max_side_traces => 128 => 128
  opcache.jit_prof_threshold => 0.005 => 0.005

Re: PHP is worth learning and using

#290
This conversation gets so vitriolic every year or so when it comes up. I'm temped to go argue in the threads, bust instead I'll just share my (recent) experience with PHP in case anyone is actually on the fence rather than here to flame.

I started out doing PHP back in the everything-is-WordPress heyday. It was easy to SSH/FTP directly into sites and edit things live, and that was also a very normal thing to do. I got good at PHP and felt kind of defensive when people said how bad it sucked. Right tool for the job and all that. But, after some time doing it, I knew I wanted to break out of my PHP shell and learn another language. For some reason I felt like I could only pick one more language to learn, so I was hesitant to do so. I ended up going with Ruby. Only then did I understood what all the crap talk about PHP was about. It's probably both a language problem and an ecosystem problem. The ridiculous, complicated iteration over deeply-nested array-dictionary-combo data structures with various counters stuck in local variables here and there that I had previously considered normal vanished before Ruby's sleek Enumerable module. Of course you can code better PHP and avoid writing those kludges, but as a junior coder, that's the thing that stuck out to me when I switched from a PHP shop to a Ruby shop. Kludges and the worst inherited Frankenstein projects of my career. I swore I'd never work on PHP code again.

I spent several years doing Ruby, and along the way picked up several other languages and now can't fathom why I originally had such hesitation to pick one to learn. After gaining enough experience to be a senior engineer, a friend recruited me for a job doing PHP. This was at a big company with tens of thousands of enterprise customers, high-scale stuff. The money was good, and I had heard a lot about how PHP had cleaned up its act since the 4.x days. It's object oriented now and has a proper standard lib! I spent 3 years there, and I have to say the engineering talent there was good. Many ideas from other languages like Ruby's Enumerable had been replicated in our toolkit.

However, the vast majority of the code was still weird data structures that are unique to PHP development because of its lack's both real arrays and real dictionaries. PHP has indeed acquired standard lib, but many pieces of it still have a crap implementation. It's like they went out of their way to make lousy APIs for things like dates, times, and durations. In every other language I've used, you can easily compare time durations (is 1 hour longer than 1 minute?). PHP DateIntervals are not comparable. The API for creating a new DateTime object at a specific date is still to pass in a specially formatted string. Or, if you don't like that, you can create a DateTime for "now" and then mutate it to set the date. They may be adding language features to catch it up with other languages, but it seems like they're obstinately doing it in the most PHP-like way possible

Long-lived resources like database connections, Redis connections, etc. plagued us. We had a whole middleware in our stack dedicated to holding open proxy connections to things like MySQL. The thing that PHP enthusiasts say make it so attractive (edit, save, refresh) also bites you in the ass because PHP processes spin up and die with each request. There is no long-lived process holding onto those resources.

As of 7.3, It was still the same old PHP I knew back in 4.0. It's still crap and this time I swear I'll never work on PHP code again ;)

Post reply on HN