DEV Community

Cover image for Pitch me on PHP
Ben Halpern
Ben Halpern

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

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
 
brojenuel 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
 
jeremyf profile image
Jeremy Friesen

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.

I have to wonder how much of that was the massive flash-bang of Django and Rails showing up; and both of those coming not from the coast of the US but from the midwest. They also showed up at a time, if memory serves, of folks hitting the "time to upgrade PHP versions and I know where all the bodies are, maybe something fresh?"

But yeah, the hate on PHP is unreal. I mean it's not like it's Perl or something (just kidding; use the language you know and love).

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
Technical John • 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
 
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
 
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
 
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
 
jeremyf profile image
Jeremy Friesen

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

Then I'd be out of job 😜.

Collapse
 
wiseai profile image
Mahmoud Harmouch

Don't worry. It is just another project idea:

another project idea

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
 
pinotattari profile image
Riccardo Bernardini

How many other languages do you know that have a message error (partly) in Hebrew? 😁

Unexpected T_PAAMAYIM_NEKUDOTAYIM
Enter fullscreen mode Exit fullscreen mode

"T_PAAMAYIM_NEKUDOTAYIM" is transliterated Hebrew and it means "double colon" (more literally, "double two-dots") You get this message if you use "::" where you shouldn't.

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.

Collapse
 
darkain profile image
Vincent Milum Jr

There is a lot of aggressive hate for PHP for all the wrong reasons (most all link to the same article written over a decade ago that mostly doesn't apply to PHP today, or things that apply to all interpreted languages equally)

Beyond that, I'll say this: PHP has the most enterprise friendly features of any of the major languages out there today.

Yeah, I'm going to get flack for this, but it from decades of experience maintaining systems that need 100% uptime.

PHP has the absolute most enterprise friendly MySQL connector outside of the C language itself, while still having the nicety of easy string manipulation. PHP has the most graceful support for distributed SQL databases with its connector, being able to handle database server failures better than any other language.

I'll admit, I'm kinda biased in this regards, however. As I'm the one that helped bake in some of that functionality. There are some extremely rare bugs in MySQL/MariaDB that can entirely hose an application server. I had one of these such bugs take out an entire fleet of application servers, getting them all in a locked state, essentially the DB DoSed the application servers.

Thanks to some of the additions I helped with to implement in PHP's connector, this is no longer an issue if the connector is configured properly. However, these same fixes don't exist in other languages like Python or JavaScript. DevOps generally just rely on "oh, it broke, let's reboot and hope it doesn't happen again" instead of doing the full investigation into the language's source code itself, the connector, and the database's source code.

Having done all that work, I know undoubtable that PHP can handle a fair bit number more failure scenarios than other languages, having done this at scale for 15+ years.

So yeah, if you're just starting out and have a single app server and a single database and rebooting them is fine, then maybe this isn't an issue. But if you're running thousands of servers at scale and need reliability and uptime, PHP's ability to horizontally scale easily mixed with its MySQL connector's ability to gracefully handle more situations makes it prime for very large workloads.

Its not obvious up-front, but PHP has more enterprise grade features than just about anything else out there.

Collapse
 
crowdozer profile image
crowdozer • Edited

What it does: It was designed to add server side functionality for webpages but it's grown to do a lot of things. You can build pretty much anything with it these days. (Okay, maybe not anything, but a lot of things.)

Why one might prefer it:

  • It's remarkably easy to pick up
  • It doesn't have annoying build processes or compiling to be done
  • It has a huge community with many mature projects and frameworks
  • Just about any webhost will support it natively given its popularity
Collapse
 
bobbyiliev profile image
Bobby Iliev

In addition to what has already been mentioned, this guy here levelsio makes $3.15M per year from a couple of SaaS projects, all written in PHP and often just a single index.php file. Pretty impresive for a language that "dOEsn'T sCAle".

Collapse
 
jamesnm profile image
James Moore

Personally, I've never worked on anything that couldn't be accomplished with PHP. I think the reason I love the language so much is due to the Laravel Framework and Jeffrey Ways tutorial site Laracasts. Laravel is the best framework I've gotten to work with to date. Everything is just so readable, I have yet to see anything else that looks as pretty as Laravel code. The framework really does come with all the batteries included. Not sure how to do something? There is probably a laracasts video for it, and you'll be able to find it in a jiff due to Jeffreys great ui/ux on the site. Laravel docs are also incredible. So ya, Laravel is the selling point.

Collapse
 
saadchaay profile image
Saad Chaay
  • 1 It’s an Open-source Language
  • 2 It is plain-sailing to use
  • 3 Upgradation in PHP software is a lot easier
  • 4 PHP resources are obtainable easily
  • 5 PHP Web Development is Cost-efficient
  • 6 PHP language helps to decrease the time of web development
  • 7 Codes include high flexibility and adequately simple integration feature
  • 8 PHP programming language also helps in web hosting
  • 9 High-performing PHP websites help businesses to retain customers
  • 10 Development Time is Less with PHP

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.