DEV Community

Discussion on: Pitch me on PHP

Collapse
 
wesen profile image
Manuel Odendahl • Edited

I've been using PHP since PHP2 (!) days. I did a serious site with it back in 2010, and am back into it after a 10 year break on a wordpress site. (I don't want to toot my horn, but I want to put this a bit into perspective: I'm a huge functional programming fan, I've written web applications in Common Lisp, python, node, C (!), perl, java, scala, C# over the years).

Things I like about PHP:

  • cgi-bin lifetime model. No garbage accumulating over time, no weird runtime dependencies and side effects: easy to scale horizontally, easy to refactor individual routes or subsystems.
  • fast. you can easily compile your code using a code cache. I use that to compile down intermediate languages (say, mustache) to JIT code.
  • it has had all the tools necessary for clean programming since PHP5: classes, traits, closures, introspection. Hate about the standard library or the garbage code out there all you want, it actually doesn't really matter. You could always write nice fluent APIs and use the introspection capabilities to do metaprogramming. Out of this came frameworks like laravel and co.
  • tooling is decent: debugger, profiler, compile cache, modules for everything out there, unit testing frameworks, package manager. Not the funkiest, but they are all reliable and get the job done.
  • big community of competent programmers (in Europe especially). For some reason, PHP hate is turned up to 11 in the US. In germany, poland, ukraine, people use it and move on and have done so since 2000.

The main two for me are the speed and cgi-bin lifetime. Most of the reasons people hate on PHP are kind of non-sequiturs. I don't care that people find it easy to write bad code in PHP, I have all the tools I need to write good code, and bad code I can easily isolate, contain and replace.

I assume this is directed at someone with programming experience going into PHP. I would be quite wary giving PHP as a language to a beginner, without proper guidance. But what language is good for a beginner is a topic for another day!

Collapse
 
pierrewahlberg profile image
Pierre Vahlberg

This. It has been a really interesting journey to debug node memory leaks that could go on for weeks without crashing or crash four times an hour. This is rare (but ofc possible) with php by design being request scoped.

The typing issue is interesting. Its a script language with types added, to some extend. I see it as TS is for JS, more of a tool to impose clean code and better structure and self documentation than something that "makes you write bug free code".

Php can be really fast, but as with any tool you are the assembling man and feel free to mess it up here too. Its neither harder nor easier imo.

The most misunderstood thing is probably all the new devs who pick php up as first language and then they find something like Golang or C# and thinks that that solves all their issues and they bash on php. I'd say no language is better than the programmer and you should learn as much as you can about how to use the language properly.