DEV Community

Cover image for Pitch me on PHP
Ben Halpern
Ben Halpern Subscriber

Posted on

Pitch me on PHP

Part of a new series! Feel welcome to dip in and weigh in on a past question.

Let's say I've never used PHP before. Can anyone give the run down of what the language does and why you prefer it? Feel free to touch on drawbacks as well.

Top comments (72)

Collapse
 
lionelrowe profile image
lionel-rowe
  • Every file starts with <?php, so you never forget which language you're writing
  • Every variable starts with $, so you always feel rich
  • It's full of surprises, like operators that sometimes return different types even when the operands are the same type
  • Calling a string with some parameters is completely valid thing to do if a function with the name of that string happens to be in scope
  • Telling people "I'm a PHP developer" is a great way to get sympathetic looks and heartfelt "thank-you for your service"s from strangers
  • If you pronounce the language name as if it's one word and say it really fast over and over again, it sounds like letting the air out of a balloon *php-php-php-php-php-php-php-php-php-php-php-php-php-php-php-php-php-php-php*
Collapse
 
joelbonetr profile image
JoelBonetR 🥇

😂😂😂 10 out of 10 experts consider this a top comment.

Collapse
 
jenueldev profile image
Jenuel Oras Ganawed

oh yes, I feel rich heha XD

Thread Thread
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
kristinegusta profile image
Kristine Gusta

This might have been the greatest comment I've ever read here. I'm sold hahah!

Collapse
 
gsheet2web profile image
GS2Web SaaS

Nice observation !

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.

Collapse
 
datmt profile image
Mạnh Đạt

• No compiling
• Live bug fixing on prod
• Cheap hosting
• WordPress
• Abundant of devs

Collapse
 
lionelrowe profile image
lionel-rowe

Explain "live bug fixing on prod"? Is this a tooling thing?

Collapse
 
datmt profile image
Mạnh Đạt

Hah, it's a joke because you can vim and edit the code live. It's risky tbh. There is no recompiling needed

Thread Thread
 
lionelrowe profile image
lionel-rowe

Ahh I see. I guess that's similar for a lot of interpreted languages/runtimes, though (at least ones that use the same one-process-per-request model)?

Thread Thread
 
datmt profile image
Mạnh Đạt

Exactly :)

Collapse
 
stojakovic99 profile image
Nikola Stojaković

Live bug fixing on prod

This is not a plus, except if you have a very small website which doesn't have much visitors and you can afford breaking things from time to time.

Collapse
 
matthewbdaly profile image
Matthew Daly

Modern PHP isn't a bad language. It's just been given a bad name by the lowest tier of WordPress plugin installers who call themselves developers. If you don't touch WordPress with a bargepole and work exclusively with a modern MVC framework you can have a pretty decent experience with it.

The modern PHP ecosystem is pretty nice. Composer is about as good a dependency handler as I have seen elsewhere, and these days most packages you may find are decent quality, typically with proper tests, and static analysis is becoming increasingly widespread.

The tooling is pretty decent too. I use Intelephense in Neovim and that gives me a good experience. I find Psalm incredibly useful too.

There's also plenty of decent content management systems available. I really like Statamic - it's a much better developer experience than using WordPress, and although it comes with a price tag, I found it covers everything I typically need out of the box, whereas WordPress needs several paid plugins for most use cases.

Collapse
 
m4rcoperuano profile image
Marco Ledesma

I’ve had a joy working with php for the last 4 years (it was also my starting language about 10 years ago, before I switched to C#, Objective C, and Java). Overall, modern PHP is a lovely language to work with. Though, I probably wouldn’t use it as much if it wasn’t for Laravel. But I could say the same for C# and .NET, or Swift and UIKit. What matters is, how can I achieve the app I want to build, while all the boilerplate like Auth, AuthZ, ORMs, etc. are all handled already.

I recommend anyone to try PHP and Laravel. It’s hard to go back.

Collapse
 
simeg profile image
Simon Egersand 🎈

It has a consistent API!

/me fleeing

Collapse
 
dhravya profile image
Dhravya

lollllll is it not consistent? I'm not familiar with PHP, only ever wrote a few lines, I've heard that it's a "really bad language" (especially on tech youtube) and that i should stay away

Collapse
 
abhinav1217 profile image
Abhinav Kulshreshtha

@dhravya Don't trust simply on the basis on what you hear, There is a lot of hate going around for php, but there is a reason It is still going so strong. Also These hate comes from old php (php <=5). The php that you would learn today is completely different language, not just an incremental upgrade. From personal experience, PHP-8 is almost as good of experience as Java J2EE for large scale Application ( now known as Jakarta EE, not to be confused by similarly named Apache Jakarta).

About language inconsistencies, it will make sense when you learn that it was borrowed from underlying system (c or perl depending on module. ). And regarding the community inconsistencies like different framework had different coding guidelines ( mostly for those which existed before PSR), That is true for almost any language (except for Java, Those guys created strict coding guidelines from the day 1). ANSI-C is quite different Turbo-C, Comodor basic was quite different than atari-basic even though they are both based on MS Q-basic. Now, almost all frameworks are getting streamlined in coding guidelines by adopting PSR at some level.

I highly recommend you to watch 25 years of PHP from its creator Rasmus Lerdorf, During lunch on some weekend, as a casual watch recommendation.
Those who say "It's a really bad language" has never learned php properly enough. Sometimes not all book should be judge by its cover alone. PHP as a language might feel weird at first, But it is a very practical language. Going through the underlying c code, is also an awesome experience, you will learn a lot of micro-optimization tricks which can be translated into any language you work with.

Collapse
 
wesen profile image
Manuel Odendahl

Don't take people's opinions on programming topics too seriously, form your own opinion. Not that you should look into PHP, but if you don't understand the reason why someone thinks a technology is bad, it often means the person stating that actually doesn't know either.

Thread Thread
 
simeg profile image
Simon Egersand 🎈

+100. Don't listen to me :D I made a joke. PHP is (was?) known for having inconsistent API but I am not an PHP expert by any means.

Thread Thread
 
pinotattari profile image
Riccardo Bernardini

I have some experience with PHP, although I wouldn't call myself an "expert." However, the inconsistency of the API is the first thing I noticed. Ruby has been designed with the principle of "minimal surprise," PHP seems designed to maximize the surprise.

Fortunately, there is a nice manual online, without that programming in PHP would be a nightmare.

Thread Thread
 
wesen profile image
Manuel Odendahl

There's also some good replacements, for example the laravel helpers. I very rarely use the standard library.

Thread Thread
 
jacekandrzejewski profile image
Jacek Andrzejewski • Edited

It does have inconsistent api for functions, however the reason is that function names are same as underlying libraries function names.
So there is strpos and str_replace (str meaning string), but they differ in naming because strpos is from one library and str_replace from other.
That is the short explanation at least.

Collapse
 
arpple profile image
Arpple

example from built-in function of core php
array_map receive callback first, array second
array_reduce receive array first, callback second

there are quite a number of this kind of inconsistency around

Thread Thread
 
ltsochevdev profile image
Sk1ppeR

Well you just lack experience if this is your biggest pet peeve. I agree, it's not a perfect system, but if you only pass an array to array filter it will filter out falsey values without you having to specify a callback. There's benefit in that

Thread Thread
 
arpple profile image
Arpple

this is not the biggest but it's the context of what I replied to.
and if array_filter have benefit of using array first, why not all other functions do the same?

Thread Thread
 
ltsochevdev profile image
Sk1ppeR

Either way, if you are coding in anything other than Notepad, your IDE will most likely help you with the argument order so in that regard, it really is a moot point. Most frameworks have all of this abstracted already. They also abstract strings. I don't see it being much different than Java world. Nobody codes in plain Java nowadays. Everybody simply learns the spring framework and "the spring way of doing things" and that is it.

Collapse
 
joelbonetr profile image
JoelBonetR 🥇

People say the same about almost any language.

You can think on it as Python example, it was released in 1991 yet it was considered garbage by many people, something that you know it exists but don't even consider using.

Two decades after it became one of the top languages to consider.

Trends are trends and community hype is present as well, check your sources, search for information, try it yourself and take your own conclusions.

Remember that is better to say "I don't like Java because it's verbose" than saying "Java is a shit"

Thread Thread
 
dhravya profile image
Dhravya

Yep, I agree. I think I heard a saying on the lines of "If a language isn't hated, it's bad"

Collapse
 
datmt profile image
Mạnh Đạt

Making decisions based on the opinions of so-called "expert" is risky

Thread Thread
 
simeg profile image
Simon Egersand 🎈 • Edited

Totally agree! See my response above. It was a joke. I'm not a PHP export by any means so don't listen to me. It was many years since I last used it :)

Collapse
 
matthewbdaly profile image
Matthew Daly

I used to use Django and always wanted to work with it professionally, but reluctantly applied for PHP jobs earlier in my career because that's what there was where I live. At my second web dev job (not second overall as it's a second career for me) I was mostly working solo, and used CodeIgniter for some projects, but it became obvious quite quickly that it was a Fisher Price My First MVC Framework, so where I could I used Django instead - it was easier to manage dependencies, far easier to write tests, and had the killer feature of the built in admin.

Fast forward to 2015 and after years of wanting to drop CodeIgniter completely and move to a more modern PHP framework for new projects, we made the jump to Laravel, and it was the first PHP framework that was good enough that I felt comfortable using it for everything. I haven't used Django since.

Thread Thread
 
technicaljohn profile image
John Holcomb • Edited

I know Laravel is big and most people know it, but I had a similar experience with Yii. It has most of the comforts of Django, but PHP.

Collapse
 
n8chz profile image
Lorraine Lee

Hosting for PHP is basically a commodity. The number of providers is large and the product is largely the same and you know what to expect. I find other types of web hosting product to be unfathomably complex, with byzantine pricing tiers. This may be because I'm old and therefore not very tech literate, but PHP hosting is a product category I more or less understand. At my IQ level, containers and droplets and other abstractions seem like a conspiracy against comprehensibility.

Collapse
 
aturki profile image
Ali Turki
  • Solid OOP model
  • Static typing
  • Does well its job (server side web dev)
  • Enterprise ready
  • Strong community
  • Plethora of tools to ensure quality
Collapse
 
wiseai profile image
Mahmoud Harmouch • Edited

According to w3techs, php is used by 77.4% of all the websites whose server-side programming language we know.

I am going to pick up a book and start learning php because it is here to stay.

Edit: Wouldn't it be a cool idea to reinvent Forem with Php?

Collapse
 
n8chz profile image
Lorraine Lee

Yeah, but how do we know? The letters "php" in the URL?

Collapse
 
wiseai profile image
Mahmoud Harmouch

Yup! That's one way to find out the language being used. Additionally, If the website is open-source like Forem, then you go to the place where the code is being hosted and find out what you are looking for. Besides, the following is a list of websites that you can use to gather information about a particular domain name, like, for example, dev.to:

In cybersecurity, gathering such info is known as reconnaissance or recon for short. I am not a lawyer myself, but I think recon is legal since you are just sniffing what is being cooked unless you take illegal actions based on collected information, such as exploitation. However, it is just a matter of opinion; the correct answer thought is to consult a lawyer to look up the laws that are tied to a specific region and vary from one place to another.

Collapse
 
aswierc profile image
Artur Świerc
  • static typing
  • symfony framework (based on java spring)
  • doctrine orm (based on hibernate)
  • you don't have to guess if the file is an interface abstract or class
  • ddd, cqrs, ports and adapter, other good practices are familiar in php world
  • phpunit, behat, phpspec - tests tools
  • composer (like maven, npm)

I'm php dev from over 12 years, I didn't touch wordpres yet.

That's enough to know that is enterprise stack.