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.

Discussion (69)

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
wesen profile image
Manuel Odendahl • Edited on

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 on

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

It does have inconsistent api for functions, however the reason is that function names are same as underlying C 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 on

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

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

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
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
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
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
software_writer profile image
Akshay Khot • Edited on

I didn't care that much about PHP but learned just enough of it so I could read the Laravel source code, which is one of the best-written codebase out there that also reads like prose and is just a pure joy to read.

Even though I work with Rails at my day job, absolutely love Ruby, and don't see myself programming in PHP any time soon, I have learned so many valuable things about writing software well, by reading Laravel's source and how much care, detail, and attention Taylor Otwell (creator of Laravel) put into it.

This may sound too lofty, but at this point I've almost made it a habit to read at least some piece of Laravel code, be it a method or a class, or even documentation before going to bed. It just makes me happy.

github.com/laravel/framework

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
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
crowdozer profile image
crowdozer • Edited on

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
taufik_nurrohman profile image
Taufik Nurrohman • Edited on

You can have class, constant, function, method and property with the same name.

$foo = new foo(); // class `foo`
echo foo; // constant `foo`
foo(); // function `foo`
$foo->bar(); // method `bar`
$foo->bar; // property `bar`
Enter fullscreen mode Exit fullscreen mode
Collapse
jeydotc profile image
Jeysson Guevara

Do you consider yourself a good engineer? Well, this is the chance to demonstrate it. Here's a language that has almost no rules, you can make real atrocities and yet make it work. The only thing that separates a horrendous, lovecraftean mess from an elegant and well engineered solution is YOU.

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
wadecodez profile image
Wade Zimmerman

PHP is the only language that tries to improve. Other languages force the whole community to adopt design flaws. Also PHP stands for "PHP: Hypertext Preprocessor". Don't ask me what PHP stands for.

Collapse
leob profile image
leob

I wouldn't pitch PHP but Laravel, a very well designed framework. But, PHP itself has also improved by leaps and bounds over the years. It's like Javascript - there's the good, the bad and the ugly - just as with JS, just use only the good parts of PHP.

Collapse
hanpari profile image
Pavel Morava • Edited on

It is a wonderful language and it is growing in popularity. Both my statements are equally true.

tiobe.com/tiobe-index/php/

pypl.github.io/PYPL.html

To be fair, it doesn't need a special template language like the other languages do.
And contrary to Javascript, one can choose an alternative anytime.

Collapse
liviufromendtest profile image
Liviu Lupei

We all know PHP gets a lot of hate.
But it makes it really easy for a beginner to build a web project.
You might hear Junior Developers saying that PHP is slow, but they might forget that Facebook ran on PHP for a long time, and they're still using it in many components.

Collapse
jacekandrzejewski profile image
Jacek Andrzejewski

Pros:

  • gradual typing (you can ignore types and add them over time later)
  • std library with many useful functions that I wish c/c++ had this easy to use
  • evolves pretty fast
  • very fast (vanilla php+nginx can respond with hello world in 4ms, going with Laravel under 50ms doesn't require much work)
  • steals good syntax from other languages
  • has magic and metaprogramming (read up on __get, __invoke and "Variable variables")
  • good docs
  • great dependency manager (composer)
  • amazing tooling (code style, static analysis and amazing automated refactoring where you can migrate big project between frameworks in a week [Rector])
  • multi-paradigm, so you can be OOP or functional (kind of)
  • has traits (like mixins

Cons:

  • magic and metaprogramming can make code extremely hard to read and debug [as example you can call function by "functionname"(args)]
  • default type casting
  • legacy code is so bad that satan laughs whenever someone has to work on it (or maybe he wrote it)
  • sometimes inconsistent, sometimes consistent
  • quite a bit of legacy syntax
  • pure php tutorials online are mostly outdated by 10 years at least
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
Collapse
nashpl profile image
Krzysztof Buczynski
  • easy to use as long you have basic programming experience but hard to master
  • Laravel is a thing
  • comes with Ubuntu which is preferred OS i work on.
  • Telling people that I do PHP make them cringe and it hilarious
  • rich community
  • perfect server side language in my opinion
Collapse
abhinav1217 profile image
Abhinav Kulshreshtha

There is an old video from creator of PHP, Rasmus Lerdorf. Its called 25 years of php. All I need to pitch for PHP is to watch the video.

The old school programmers stories, back when people used to program to solve real world problems and have fun while doing that, is something I have always been fascinated about. But Rasmus Lerdorf takes it to all new level. Suddenly, all the memes and jokes about how weird php language is nullified, you start realizing how practical language actually is.
He goes through what php was (php<5.x) what php will be (php >7.x). It is surprising that they managed to completely reinvented the language, yet managed to provide a proper upgrade path. Unlike python which was a mess for switching from 2->3.

On top of that, he doesn't just say that there are performance improvement, he talks about how less cpu resource means less carbon emmisions. He talks about how someone created a relief service in few hours after the country was hit with earthquake.

Collapse
link2twenty profile image
Andrew Bone

Looking forward to the Perl CGI one of these 😅

Collapse
atherdon profile image
Arthur Tkachenko
Collapse
johnhalsey profile image
John Halsey

PHP is a great language to use and works fantastically with frameworks like Laravel.

PHP is good for beginners and my favourite thing is that the name PHP is, itself, recursive.

Collapse
darkterminal profile image
Imam Ali Mustofa

I have no idea... but I get a job, have a nice house and have a happy family. I learn in many things but i falling in love with PHP as a dot in circle lens.

Collapse
jovialcore profile image
Chidiebere Chukwudi

Do you know that "php" is pronouced same way backward ?

Collapse
golangch profile image
Stefan Wuthrich

For PHP you can finde the best Job Board for PHP Jobs
Just the code running the board is NOT starting with <?php ;-)

Collapse
brojenuel profile image
Jenuel Oras Ganawed

LARAVEL

Collapse
mhmxs profile image
Richard Kovacs

One of the languages which would't exists.

Collapse
karandpr profile image
Karan Gandhi

Guaranteed jobs :D.

Collapse
stresseddev profile image
Stressed Developer

You can use Laravel.

Collapse
tmchuynh profile image
Tina Huynh

What are your thoughts on PHP?

Collapse
sentadoensilla profile image
sentadoensilla

Compatibility
Simplicity
You can code it as you want

Collapse
mono13th profile image
Moch. Sudharmono

Wordpress uses PHP!