DEV Community

Cover image for PHP... yay or nay?
lizziekardon
lizziekardon

Posted on

PHP... yay or nay?

We usually see two camps:

  1. PHP is way better than it used to be, and huge sites still run it (Facebook/Wikipedia, etc...)

  2. PHP always sucked... anything is better.

I want to know, which side are you on? What your thoughts on PHP?

@jacobian for scale...

Top comments (30)

Collapse
 
jck profile image
Jack

I believe that PHP has progressed and only become better than it used to be. With PHP 7+ and frameworks like Laravel & Zend, PHP can produce high-quality, maintainable, and respectable codebases.

It's not always the right tool for a lot of jobs, but it can be used with great success.

Collapse
 
rashtell profile image
Engr AbdulRasheed Tella

I believe how good a programming language is dependent on how large its community. The ease of using one language depends on how much help you can get from users of such language. Thats one of the reasons behind languages like JAVA still topping the chat at the expense of more flexible languages like kotlin. I personally enjoy PHP. Its great for both functional and object oriented programming. It has great frameworks and libraries e.g Laravel, Symfony etc. It can also be used for data driven websites like facebook. Did i mention its super easy to learn and work with.

Collapse
 
lizziekardon profile image
lizziekardon

πŸ‘πŸ‘πŸ‘

Collapse
 
buphmin profile image
buphmin • Edited

PHP is fine. I have been using it for 5 years. My intro into it was with Symfony and a best practice doc so I got to see how good it could be used. PHP has some quirks but overall it is easy to develop with for both web and non-web tasks.

Now the problem with PHP more than some other languages is it's opportunity for abuse. The other day we upgraded to php 7.2 and some things broke. It turns out you used to be able to declare a string and used it as a associative array (hash map).

//please never use this, it is bad :( and will actually not work in php 7.2+
$myArray = "";
$myArray["product_id"] = 12345;

PHP is littered with weird things like this, but ultimately it is up to the developer to not do dumb things.

Collapse
 
vlasales profile image
Vlastimil Pospichal

This code will generate big problems in future. Never use it.

Collapse
 
buphmin profile image
buphmin

I'd never! That does not stop others though unfortunately.

Thread Thread
 
vlasales profile image
Vlastimil Pospichal

Please add comment "Never do this!" into this part of code. Somebody may read this like a pattern.

Thread Thread
 
kevinhch profile image
Kevin

Why this code is bad?

Thread Thread
 
vlasales profile image
Vlastimil Pospichal

String is not an array.

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

PHP is way better than it used to be. OOP is perfect, database connectors too, super modules for maintaining XML, JSON, CSV,...

PHP is not just one language. I use SQL, XPath and XSLT in it as well. This combination is very cool and speed is like on steroids.

Collapse
 
samuraiseoul profile image
Sophie The Lionhart

OOP in PHP is not perfect. For instance, an interface can define the constructor's signature.

interface Foo {
    public function __construct(SomeDependency $someDependency);
}

This isn't allowed in most languages(maybe any others) and is pretty against SOLID principles.

Collapse
 
vlasales profile image
Vlastimil Pospichal • Edited

This is not against SOLID principles. Simply I don't use it.

Collapse
 
lukasderksen profile image
Lukas Derksen

I've shifted from side 2 toward side 1 in the last months. Don't get me wrong, there are a lot of PHP programs that are absolute shite in terms of code quality. But with the introduction of PHP frameworks, I've come to love the possibilities PHP has to offer. They're still just as easy to deploy and it's easier to create large enterprise projects without losing control of the code quality. And let's be honest, the same thing goes for javascript. There are still loads of people hating on javascript for what it used to be. But since ES6 it's so much better and the frameworks only improved on that.

Collapse
 
sadick profile image
Sadick

Hey @lizziekardon . It doesn't matter which side someone is on.There cannot be a healthy debate when the purpose is to put people into camps. Every programming language sucks depending on who you ask. Let's say i have a problem that i need to solve, I could solve it using any of the existing languages. What would make me choose one particular language and not the other is constraints i.e. performance , size, elegance, ease of implementation e.t.c. For some problems PHP is still a better option but we would not admit it since its cool nowadays to hate on PHP.

Collapse
 
lizziekardon profile image
lizziekardon

Don't need to put anybody into camps, just sharing what I've found! Would love love love a healthy debate, that's why I used the tag ;) -- what are your thoughts? sounds like you're all for it if it's helping to solve a particular problem?

Collapse
 
sadick profile image
Sadick • Edited

I don't mind using PHP at all. At the end of the day what matters is the user experience. Developers care about this stuff but our users don't. If using PHP would give a better user experience am all for it. But from the title it's a yay or nay for PHP. I feel like that doesn't leave much room for discussion.

Thread Thread
 
lizziekardon profile image
lizziekardon

nice. good answer! thanks for sharing.

Collapse
 
_ezell_ profile image
Ezell Frazier • Edited

I started off with PHP, but prefer Node over it and just about anything else imo.

The pros of PHP as well as just about any other server-side language over Node is short and sweet; better built-in methods. String methods, object methods, etc.. JS is rapidly catching up here, but if I found myself wanting more for less, I'd probably move over to Python.

Anyways, PHP is fine for most use-cases, but I've come to love Node for a few things:

  1. NPM (there's just about a package for anything)
  2. The .js file IS the server (no need for Apache/Nginx)
  3. TypeScript
  4. Inherently asynchronous (it takes a lot for the server to block requests)
  5. It's generally the default/starter tech for cloud function services (firebase)
  6. Native server-side rendering support for front-end libraries (vue, react)

The combination of the above points are why I struggle to find much of a reason to use PHP or any other server-side languages.

But if the use-case is to simply model and serve content, just about any language will do the job, including PHP.

Collapse
 
_hs_ profile image
HS

Well docker is very much needed even for PHP. Testing, staging, production, config this, config that... As opposed to other languages where i pretty much deploy app as is whitout configuring other stuff. Now this depends on your project but lately I was using .NET Core on Azure. Yes, we did have also Angular frontend which is 2 languages for one app as said in the tweet. But also we had mobile app and Xamarin was used which is still C#. Now only thing we did was variable replacement during deploy which is handled by azure, you just put in variable name and value for each deployment you need. So there was usualy couple of variables to handle like DB connection string and that kind of stuf. It takes about 2 minutes to setup all vars for 3 kinds of deployment. So for me there's nothing PHP offers me in those terms. Other than that I dislike the syntax. Java and C# have array.stream().filer() and array.select() respectively which to me is much nicer than array_filer(array, "function name"). Ruby, Scala, Kotlin, and many more have similar style while PHP keeps it C-like. That's why I disslike the language compared to others. Now, it's still a good language and has its perks but it's probably more about the preference(taste) tha other stuff.

Collapse
 
funcke profile image
Jonas Funcke

PHP has its flaws and syntactical problems. That's true. But on the other hand it is an easy-to-learn language with great usability for newbies as well as for more experienced programmers.

It is true that, especially with the functional approach and the concept of globals (like the old mysql_ driver) were huge problems and a syntactical pain in the ass (at least in my opinion).

But since PHP 7+ not only improved performance and requiring other .php files (waaay more to come with 7.4 - preloading- and 8 -JIT) but also with more and more libraries adapting an object oriented (PDO) or more local-scoped (mysqli_*) approach the weird and ugly looking procedures in PHP have started to disappear.

Collapse
 
danjconn profile image
Dan Conn

I have not used PHP since PHP 5. I have heard it has improved a lot. Even in PHP 5 I built some very simple things and some enterprise scale fully automated systems.

My main issue with PHP is also it's strength. It's very easy to get going.

It works as a positive in that you can get results quickly with little knowledge.

But this is also a negative because you needed to know a lot about the language anyway to ensure you were using it safely.

For example knowing which one to use out of mysql_escape_string, mysql_real_escape_string, or msqli_real_escape_string relied on you knowing which one was safe!

I know the offending ones were removed from PHP 7, but still, newcomers drawn to its ease of use may not have been aware of this (are there other examples still around though?).

I think if you know what you're doing with it and are sure you understand the pitfalls then great, for me personally, I'm happy to stick with Java and Python for now :)

Collapse
 
makiten profile image
Donald

I don't really mind it, but I hardly use it anymore, since I can accomplish my tasks with other languages. I use languages I don't like (JavaScript) all the time, so the main reason I don't really do PHP much anymore is because there aren't jobs asking for it. 10 years ago, they did, but it's far less common except in the local startup scene where the pay for PHP is woefully low.

Collapse
 
moopet profile image
Ben Sinclair

As someone who uses PHP every day, but who used to use real programming languages, PHP is...

wait, can you see my bias showing?

PHP is pretty awful, but being totally fair, so are a lot of languages. They're just awful in different ways.

If I could have the last decade of my life over, would I try to avoid PHP? Yes. Yes, I would.

PHP is where the jobs are, though - at least the jobs I've been able to get. It's still everywhere.

And it is getting better, just not as quickly as it should. It still has dreadful new features added to it all the time, and it's still plain bonkers. The only modern frameworks that are any good are the ones that try to corral its bits and pieces into something stricter. And hay, why not use something stricter in the first place?

Collapse
 
aminnairi profile image
Amin

Daily Node developer here. Sometimes I miss PHP for its meta programming game that is way better than JavaScript IMO. That's why there are awesome Frameworks like Laravel which I use for my personal projects. I tried to write a tool to generate GNU Linux i3bars in PHP and it was so easy to add features but when I started adding asynchronous programming it became a lot harder than I though. I finally used Node but its OOP is not on point compared to PHP. There is no better language, it really depends on the situation. I sometimes overheard people saying that PHP sucked but as for any language I honestly think that no language suck, what makes us think that is because we didn't choose the right tool for the job. JavaScript has a better set of tooling for functional programming than PHP for instance.

Collapse
 
andrewbrooks profile image
Andrew Brooks πŸ‘¨β€πŸ’»

Modern PHP is great. Especially when using a framework like Laravel. The Laravel docs are amazing too. Very detailed and organised.

Collapse
 
ssimontis profile image
Scott Simontis

As the guy who generally ends up sysadmin for PHP sites, I don't like it. So many fun performance issues to hunt down, so many security flaws to worry about, I never feel at ease when I am in charge of a PHP server.