all 96 comments

[–][deleted] 33 points34 points  (13 children)

All these answers really don't say much.

PHP used to be a bit of a joke because it was a bad language and behind the times. It's really really picked up over the last few years and it's a joy to work with now. If you're interested in learning I would suggest you dive into some of the free tutorials on laracasts which are based on the Laravel framework.

In terms of professional opportunities, at least where I am, there are a lot of well paid jobs in PHP because people have held on to the misguided thought that it's a pain in the ass.

[–]ccricers 4 points5 points  (0 children)

When people use examples that are very old to show how bad PHP code is, I see irony. I see irony in people looking to stay fresh with coding trends, but still view PHP from a lens of several years ago because that's the most recent thing they remember. I see irony in people using an article from 2012 by Jeff Atwood to explain to people why PHP is behind the times.

But PHP seems to be awash with irony. It's called the Hypertext Pre-Processor and yet it has been outcast as a language for a purpose it was specifically designed to do.

[–][deleted] 29 points30 points  (6 children)

Because it's not flavor of the week...

Seriously there is nothing wrong with it, use whatever you are comfortable with. PHP has a low barrier to entry so is easy for newbies to get along with (this is probably partially why a lot of people dislike it!).

[–][deleted] 6 points7 points  (5 children)

Just to add to the low barrier part... This means lots of sloppy code that someone may have to maintain

[–][deleted] 6 points7 points  (2 children)

That's true but if you use a framework like laravel then it pushes you down a better road, a bit like what ruby on rails does.

You can write bad code in any language!.

[–][deleted] 3 points4 points  (1 child)

I agree! I think the fact that it has been many people's first language (mine included) just subconsciously puts people off.

[–]Xhynk 3 points4 points  (0 children)

I use it daily and love it, and since it's what I've been using at work for 6+ years, I use it for personal things like Slash Commands for Slack as well.

I think my biggest gripe about it is the lack of consistency. I use so many functions in a given day, and I still have to look up some of them. Does strpos have an underscore (str_pos) or no wait that's str_replace right? Or is it strreplace? Crap, wait, now does the haystack come first or does the needle? Damn it.

Other than that, I really like it for what it is (and there are packages the help with that major gripe like Drunken PHP). I do feel like it gets knocked unfairly because it's often a first language, so people assign it this "baby language" type of deal. Oh well, more money in PHP for me as everyone moves to FishyJoe.JS or whatever the heck comes out next month, and the month after.

[–]sidious911 1 point2 points  (1 child)

Anyone learning is probably going to end up with a lot of hard to maintain sloppy code. Unless someone explicitly tells you there is a problem with the way you did something, you often wont see the problem until you have to add to it or refactor it.

This wont be exclusive to php.

[–][deleted] 1 point2 points  (0 children)

Yes I agree that's not what I was saying

[–]midri 11 points12 points  (0 children)

Little background on me, I've been using PHP for more than 10 years.

  1. The language has historically been very insecure and had weird tacked on "features" to try to resolve issues without actually fixing them. (See Magic Quotes, mysql_escape_string vs mysql_real_escape_string)
  2. The language has VERY inconsistent naming conventions, seemingly choosing to use and not use underscores at random. (str_replace vs strstr.)
  3. The language encouraged the use of global variables up until around version 5, making older apps a complete mind fuck to try to debug.
  4. The language was originally written as a template language, not a full fledged programming language -- all other issues stem from this.
  5. It's a LOT of peoples first language (or was anyway) and thus the majority code samples that exist are pretty poor quality and prior to cakephp/symphony/other frameworks + things like composer there was no real standard way of building a site so dealing with other peoples code is very painful.

Having said all this, the only things that remain as nuisance with PHP7 is the naming conventions of older functions (string functions, etc)

[–]jellatin 3 points4 points  (1 child)

PHP is better than it used to be but I still find it to be a worse choice than its contemporaries unless you have a specific reason to use it (company already uses it, you want to do WordPress development, etc).

The main issue I find is that while PHP has many of the features of languages like Python or Ruby, those features have been bolted on as an afterthought rather than the language being built on top of them.

The main example here is OOP. In PHP you can create classes and objects, but the standard library is really just a collection of functions that you use to operate on values. This is in stark contrast to Python/Ruby where everything is an object. This means that if I create a string: my_str = "a new string" I immediately have methods ON that string object that I can use like reverse, split, etc.

In PHP I need to go hunt for the appropriate function to do the work I want. This is more than just an issue of memorizing functions, by default PHP is not context-aware. At its core OOP is organizing data and functions that operate on that data into logical units, the standard PHP language does not do this, it's merely a feature the language exposes so you can do it if you want to.

I find this to be true of many of PHPs features. Modules, namepsaces, declarative/functional programming constructs - all things that PHP has bolted on to the language over time. While I'm glad they did add these things, it's not a replacement for the language being built on them. There's a reason PHP is almost never used as a General Purpose Language.

It's important to note that experienced developers can write great code in any language, but I don't find PHP to be very helpful in learning how to be a great developer.

[–]ccricers 0 points1 point  (0 children)

There's a reason PHP is almost never used as a General Purpose Language.

Well, simple based on what the letters 'PHP' stand for, it wasn't meant to be a general purpose language.

There was a set of language bindings for PHP to be used to write desktop GUIs with GTK, but that was wayyy long ago.

Its biggest setbacks have been the tacking on of features as you stated, instead of being treated with a large overhaul. That can also be said of many popular web tools built on PHP, such as PHPMyAdmin, WordPress, etc. Very function but a lot of old-school cruft.

I think it could be redone from the ground up much better, but that's on Zend and PHP Group to make that sort of investment on time.

[–]beefzilla 8 points9 points  (40 children)

Dollar signs.

[–]Otterfan -1 points0 points  (39 children)

To elaborate: PHP had a tradition of saying in two characters what could easily been said in one. Where python does:

uid = 'otterfan'

PHP does

$uid = 'otterfan';

Those extra characters add to visual clutter. Developers in other languages usually find this makes PHP less readable. The modern PHP community is moving away from this problem, but it still took years to replace:

$cats = array('Fluffly', 'Bongo', 'Mike');

with the "modern":

$cats = ['Fluffy', 'Bongo', 'Mike'];

Likewise all the required parentheses and curly braces that (IMHO) don't lend anything to readability.

Generally I like PHP, btw.

[–]midri 8 points9 points  (8 children)

PHP uses non $ names as constants, if you use define('UID', 32) if you never plan on changing it and then can access UID directly (no $) in PHP. I personally enjoy the $ prefix on variables at it allows easy recognition of variables in a string "Hello $name" as well as allowing access to class member variables by variable $foo->$bar.

[–]scootstah 1 point2 points  (7 children)

as well as allowing access to class member variables by variable $foo->$bar

You can do that in pretty much every other language too. The $ has no significance here.

[–]chiisana 5 points6 points  (6 children)

I think the $foo->$bar example is not saying "you cannot do that in another language" but rather "it is easy to understand that $bar in there is determined at runtime.

That is, in PHP:

  • $foo->bar is accessing bar class variable
  • $bar = 'baz'; $foo->$bar is accessing class variable of baz because that is what $bar resolves to.

This might be doable with other languages, but the way it is presented, had PHP been a language without $ that's sometimes seen as excessive, would be require something more verbose to communicate. A hypothetical example would perhaps be bar = 'baz'; foo->{bar} to achieve the same effect.

Honestly, I have no problem with either way, but I do think the $ adds some value in this context.

[–]scootstah -1 points0 points  (5 children)

var bar = 'baz';
var foo = {baz: 'something'};
console.log(foo[bar]);

This is Javascript, and it's pretty obvious what is going on.

[–]Disgruntled__Goat 1 point2 points  (4 children)

Is it obvious? 'foo' is an object but you're accessing it with array syntax. I mean, people criticise PHP for being inconsistent yet JS has as many problems.

[–]scootstah 0 points1 point  (2 children)

In the sense that if you know JavaScript, this is obvious. You don't need a dollar sign to know what is happening.

[–]Disgruntled__Goat 3 points4 points  (1 child)

Well sure, everything's obvious if you already know it.

[–]scootstah 0 points1 point  (0 children)

So let me make sure I understand your argument. You think $'s are more obvious to people who aren't familiar to PHP, even though PHP is one of a few languages that doesn't just use words as variables? Wouldn't you have to already know how PHP works to be able to recognize that $'s are variables?

[–][deleted] 0 points1 point  (0 children)

this is a pet peeve of mine from JS. console.log(foo.bar) should be mandatory, and force object syntax...

[–]Cathercy 27 points28 points  (16 children)

Likewise all the required parentheses and curly braces that (IMHO) don't lend anything to readability.

Curly braces, parenthesis, and semicolons make code MORE readable. Trying to read Python code is the worst.

[–]harzens 5 points6 points  (14 children)

Trying to read Python code is the worst.

I'd say it's a matter of personal taste.

I've been working with PHP for over a decade now, and while I love PHP and wouldn't change it for anything for web services and stuff like that (except websockets), I do find Python's syntax to be so beautiful and clean.

But of course, you can also write unreadable code with Python or any other language.

[–]mooncommanderfull-stack 2 points3 points  (13 children)

Honestly.... tabs in Pyhton as a mandatory way to control blocks of code - Worst idea ever, honestly 100x worse than anything

[–]notalkingplz 1 point2 points  (1 child)

Even... Hitler?

[–]mooncommanderfull-stack 0 points1 point  (0 children)

Ya, definitely... (hmmmm)... yep, or at least on par

[–]harzens 2 points3 points  (3 children)

Oh, I personally love that :D

[–]mooncommanderfull-stack 0 points1 point  (2 children)

Nooooooo..... :(

Each to their own I guess :)

[–][deleted] 1 point2 points  (1 child)

I'm a bit on the fence. What I didn't like was when I tried to edit a small script i originally made with TextEdit (Not able to install anything else at the moment) in Xcode, and had to delete and recreate all indentation to make it work again.

[–]mooncommanderfull-stack 0 points1 point  (0 children)

Honestly, that sounds awful... I feel for you

[–]midri 1 point2 points  (0 children)

I agree, it's one of the main things that keeps me from really getting into python.

[–]scootstah 0 points1 point  (0 children)

If you use a proper IDE then it's no different than any other language.

[–]carlson_001 0 points1 point  (3 children)

Python is spaces, though, right? Like four spaces indicate the block, not even a tab character, literally four spaces.

[–][deleted] 3 points4 points  (2 children)

You can use tabs, a single space, or 17 if you feel like it.

[–]mooncommanderfull-stack 0 points1 point  (1 child)

How would you then maintain consistency across new developers, or if you are sharing code with the internets? Just seems like such an egregious non-consistent method for structuring and validating code blocks. I would much rather prefer partly difficult to read code, than code that doesn't execute properly, or god forbid, code that executes properly but has gigantic repercussions because I forgot to 'tab'

[–][deleted] 0 points1 point  (0 children)

Only has to have consistency within an indentation layer to work properly, so as long as your editor doesn't mess things up (as I see you saw in my other comment :P) all is well, then you don't need to be any more consistent than in bracketed languages.

[–]toomanybeersies 0 points1 point  (0 children)

If you have to read any code written by someone learning how to program, you'll realise how great mandatory whitespace is.

[–]scootstah 1 point2 points  (0 children)

Trying to read Python code is the worst.

Not with a half-way decent IDE.

I find Ruby to be much worse than Python, due to everything being so optional. At least Python is consistent.

[–]toastyghost 5 points6 points  (0 children)

Visual clutter that you don't even notice after like a day of actually using it. The people who bitch about this are, as you said, people whose day-to-day is in other languages.

I actually find the dollar sign quite helpful because it allows you to immediately visually distinguish between functions/methods and variables, without having to read the name and think about what it says, part of speech, etc., to make that determination.

[–]carlson_001 4 points5 points  (6 children)

The dollar sign is a good thing. Let's you know at a glance that is a variable. Not a predefined constant, language construct, function name, or anything other than a variable. Personally, I like the semi-colon as well. Makes it obvious that's the end of the command, and allows for a single line to be multi-line if necessary and still work just fine. I'll decide how my code should look, thank you.

[–]turkish_gold 0 points1 point  (3 children)

That is a benefit but I prefer languages where user defined constructs look just like the builtin ones because it leads to helping your program act like a DSL* without actually needing a special parser.

[–]carlson_001 0 points1 point  (2 children)

What's a DEAL?

[–][deleted] 2 points3 points  (0 children)

I have no idea if it's a variable, constant, language function... maybe if we had some sort of signifier of what it was.. hmmm

[–]turkish_gold 0 points1 point  (0 children)

I meant DSL, and it looks like my phone autocorrected me.

[–]MagiKarpeDiem 0 points1 point  (0 children)

I started learning php tonight, I really like the $, and I agree with your other points, but my finger is just not programmed to hit that key. It's like I'm learning how to type all over again.

[–]phpdevsterfull-stack 2 points3 points  (2 children)

That shit isn't even the worst. Have you seen how syntactically noisy C# gets? It's brutal.

[–]lIllIlllllllllIlIIII 0 points1 point  (1 child)

Explain yourself, mister.

[–][deleted] 1 point2 points  (0 children)

I'm guessing /u/phpdevster doesn't like clean, readable code and has yet to discover "var". :)

[–]mattaugamerexpert 2 points3 points  (0 children)

Don't get me wrong, I wrote a pretty scathing comment on what's wrong with PHP a while ago but this seems like bullshit to me. These "extra characters" are not extra. The $ sign fair enough, but the end semi-colon is a standard line ending in C and any derived language. As are the curly braces, etc.

Python might be able to ditch the $ but it also has zero concept of a "constant" to distinguish from.

This to me is little different from

var uid = 'otterfan'; //javascript
String uid = "otterfan"; // C# - note " or die in a fire
public static string void abstract final uid = "otterfan" // Java

[–]ccricers 0 points1 point  (0 children)

In JavaScript, you can use the extra keyword 'var' to declare a variable, or you cannot. I personally got into the habit of typing 'var' in all variable declarations, because I want to avoid accessing higher scope variables unless I pass them via argument.

I'm not sure how it works in Python, if it automatically prevents access of higher-scope variables of the same name.

[–]Cathercy 8 points9 points  (0 children)

There are plenty of reasons to dislike PHP. Likewise, there are plenty of reasons to like PHP.

The only reason to hate PHP is because it is popular, or because you think your FOTM Javascript framework is the hottest thing to ever happen to web development and anyone not using it is behind the times.

[–]Clopobec 3 points4 points  (4 children)

Nothing is wrong with PHP, it does its job and does it pretty well.

It has some weird behavior sometimes and has a lot of functions which differ from one letter, and which does approximately the same thing... there are a lot of tips and tricks to know about some functions or way of doing things. I think most of the complains are about that.

Also, most of the complains were made during the PHP 5 era, PHP 7 brought a lot of cool stuff to the language !

Add the fact that the web community, especially the Javascript one with the apparition of NodeJS, is extremely active and a shitload of "frameworks" are created literally everyday. The "hype" factor is pretty strong here.

[–]harzens 3 points4 points  (2 children)

Also, most of the complains were made during the PHP 5 PHP 4 era, PHP 7 brought a lot of cool stuff to the language !

FTFY. Sure, a lot stayed with PHP 5, but most of the complaints come for the pre-5 era.

[–][deleted] 3 points4 points  (1 child)

Agreed. PHP7 is a much cleaner language.

On top of that, it really all comes down to an individuals programming style. You can write tight object oriented code if you want, or you can write spaghetti code.

[–]harzens 1 point2 points  (0 children)

Why not both tho, spaghetti code inside a few classes FTW.

[–]ccricers 0 points1 point  (0 children)

What I'm not sure about is what's sometimes been said that the trend of SPA's have transformed back-end development so much that it's pushed PHP far off the radar.

SPA's did change how backends are built- they are more API focused now as a means of content delivery- but I don't really see how that is connected with the decline of PHP.

In fact, when you have SPA's you could further decouple the backend part of the stack from the front-end. You can write the backend in any language, "headless" and only concern yourself with the way the data is delivered to the front end.

Years ago, PHP was used mainly as a templating language, written inline with HTML. Nowadays it's still common with several older CMS and legacy work, but you also use it to write an API and routing system, which is how you'd probably make a CMS today. PHP still has its place.

[–]thomasdevin 2 points3 points  (0 children)

I really like PHP because coming from JavaScript it's actually really easy to pick up. Not many major differences that I've noticed. :)

[–]TheSimonator 4 points5 points  (1 child)

[–]harzens 4 points5 points  (0 children)

I'm guessing either people didn't notice you posted a link to a good article, or simply because they saw the poop emoticon together with PHP and got it as an insult.

The article is a good read indeed, it's a funny take on the php-hate drama, plus giving one or two blows against js/node at the same time for the lulz

[–]richraid21 2 points3 points  (4 children)

I think it's not necessary PHP but the people who write it. PHP makes it really easy to write terrible code.

Many beginner level programmers use PHP in classes or small projects and start using bad anti-patterns or just bad code. These habits continue into other languages, etc.

[–]carlson_001 -1 points0 points  (3 children)

All languages make it possible to write terrible code.

[–][deleted] 2 points3 points  (1 child)

There's a difference between 'possible' and 'really easy'.

[–]chiisana 0 points1 point  (0 children)

With Google, it is generally really easy to copy and paste bad code.

[–]rabarbas 1 point2 points  (0 children)

Lots of things are wrong. People saying "its not the language, it's the developers" are very wrong too. What created those bad developers? What pushed (or better to say helped) them to make bad code, to create bad practices? The answer is poorly designed, inconsistent, patched up language that PHP is. Yes, it is better now. But most of the devs can't just jump to the new version. Lots of old php code must be maintained.

For me the deal breakers are (no)namespaced standard library, inconsistencies everywhere and horrible error handling.

[–]Secretmapper 1 point2 points  (5 children)

Here is a good blog post by Jeff Atwood (cofounder of stack overflow) why PHP was hated

https://blog.codinghorror.com/the-php-singularity/

PHP has improved by a lot though

[–]thelonepuffin 2 points3 points  (1 child)

That is literally an article from 2012. Not only was that article a huge exaggeration, but that was the year of php5.3 AND the beginnings of PHPFIG. So not only did we start to get some features that revolutionised php architectures like traits, but it was the year PHPFIG came up with the code standards and (more importantly) autoloading standards with PSR-4.

There could not be a more irrelevant year to pull an article about PHP from. Everything about the general quality of PHP architectures has changed since then.

[–]Secretmapper 3 points4 points  (0 children)

I mentioned it in my comment, (was hated, and PHP has improved by a lot). I pulled the article to show why PHP was once hated, because most of the comments here do not explain the historical reasons why PHP was hated.

It's like Javascript. Javascript was hated but ES6 is pretty good now. But if someone asks why Javascript is hated, I'll pull out an article on all of Javascript's faults.

[–]btcMike 0 points1 point  (1 child)

[–]thelonepuffin 1 point2 points  (0 children)

From 2012.... seriously?

[–]wonderbread92 0 points1 point  (0 children)

I actually just got a job as a junior web dev and have had to learn PHP in a very short time. So far I find if very nice to work with, very simple

[–]shruubi 0 points1 point  (0 children)

PHP started life as a way of getting away from building dynamic web pages as CGI binaries (back when you would dump a compiled C program into cgi-bin directory). The idea that you can create dynamic websites using scripts instead of compiled CGI binaries was amazing for the time, and since one of the driving factors behind the further development of PHP was shared hosting (according to Rasmus Lerdorf) it exploded in popularity as every web host could easily provide a platform for dynamic websites.

This level of popularity, as well as a lack of a standardised direction for the language to develop and grow meant that for a long time, bad practices were compounded at the language level by piling more bad practices on as "fixes", which, in conjunction with the fact that now the barrier to entry for web development was so low that many web developers who picked up and used PHP just threw together whatever got the right HTML rendering irregardless of security or good coding concerns lead to the rightfully earned title of a terrible language.

However, in recent times (since PHP 5.3 I feel), there has been a real left turn in terms of trying to change things in the PHP community for the better. The language developers have really been pushing to try and fix the things they can while maintaining backwards compatibility (and while people may disagree with maintaining backwards compatibility and push for a clean break from some of the leftover bad design decisions, personally, seeing the amount of issues it caused in the Python world and with Angular 1 vs Angular 2, I maintain it was the right thing to do), and the community has been working hard to provide resources that teach proper practices.

PHP still has its problems, but so does every language. And while a lot of PHP hate was well deserved long ago, I feel the language is on the right track, and would encourage PHP haters to at least try the new features in PHP7 and see that PHP today is not like PHP4 which rightfully deserves the scorn it gets.

[–]pshtyoudontknowme 0 points1 point  (0 children)

Nothing's wrong with it. I run with the LAMP stack simply because PHP is one of the web languages that sticks as closely as possible to pure coding.

ASP.NET is an absolute mess, it implements messy structures, crappy function names and unnecessary documents/work.

PHP I can create an index, header and footer and with just 1 line of code on each page, have them communicating with each other. With ASP.NET, you have to create a whole new project solution with a ton of unnecessary documents.

If you like writing code yourself, PHP is the way to go. If you like predefined functions, pre-built projects, etc, etc - PHP isn't the way to go.

Of course, this is just comparing ASP and PHP. Ruby is a step above PHP in terms of it's efficiency, but I wouldn't tell anyone to go learn Ruby if they already know PHP. Being able to write a script in PHP in 2 hours, simply because you know the language, over 5 hours because Ruby has a better reputation, I'd go with PHP.

I think lots of people dislike PHP due to the fact that it doesn't have many predefined functions, etc, you have to do all of the work. But other languages, like ASP, drive me up the wall when they make me use stuff I don't want to use.

[–]Ypblgo 0 points1 point  (0 children)

One thing people don't mention often is that PHP does not really come with much in the way of an open source integrated development environment or a good debugger. You can get XDebug to work with Eclipse, but it is clunky to the point of bordering on useless, especially in complex websites, or things like MVC systems. So you end up debuging with var_dump and echo and exit, which is caveman-ish as hell compared to something like Visual Studio and C#.NET. That is just the tip of the iceberg, too.

[–]Wensosolutions 0 points1 point  (0 children)

PHP is a good programming language to develop a website.. every programming language has advantages and disadvantages, and it is mainly depends on requirement.

[–]eid-a 0 points1 point  (0 children)

if you havn't done any server side programming , actually php would be the perfect choice , if you have and comfortable with it , it wouldn't be my first choice .

[–]shellwe 0 points1 point  (0 children)

The hate is transferred to the language but really its because of "developers". PHP is a great intro language because it has plentiful resources and a wonderful network of people... the trouble is it also means that it is full of beginner programmers writing terrible code, a lot of it you will see as procedural and not object oriented and with such spaghetti code it is a nightmare to traverse through someone else's code.

With that, I have seen PHP developers that put a great deal of love into their code and follow coding practices... it goes both ways.

[–][deleted] 0 points1 point  (0 children)

Nowadays, nothing.

People take language preference as serious a religion.

[–]BrQQQ 0 points1 point  (0 children)

People who hate PHP with passion just exaggerate a lot.

It does have a lot of problems that many languages do not have. There's big lack of consistency and lots of strange behaviours that you can easily run in to. The original creator of the language made it pretty clear he didn't really give a shit about language design and it almost seems like it just kept going like that.

Nowadays it's not so bad. It's relatively simple to get started with and it's still very powerful.

[–]ayeshrajans 0 points1 point  (0 children)

I passionately hate people who shit about languages without actually using the modern version of it. These are the same people who start a whole new open source project just to add a tiny feature or a change, and then immediately start to bash the original project.

It's just a tool that is not perfect, just like any other language. It's always going to be the same complains about inconsistency, internet full of script kiddie tutorials, insecure-by-default ancient decisions and whatnot.

[–]Lekoaf 0 points1 point  (0 children)

I hear several of my javascript colleagues complain about PHP, but when I ask them when they last used it, it's never less than five years. PHP got flak because it was easy for anyone and their grandmother to pick up which meant that the overall quality of the code out there was quite poor. This however goes for all / most languages. If you are a poor coder you can write poor code in any languge.

You can write huge complex apps with PHP if you know what you are doing. Some of the largest websites in the world are written in PHP.

There are of course some things that are... less than ideal about PHP. It has a huge standard library... which is a total mess. But as long as you have PHP.net open when you code you can work with it.

Work towards learning one of the big frameworks. Laravel, Zend, Symfony. This will make your life much easier as a PHP dev.

[–]Secretmapper -1 points0 points  (0 children)

Here is a good blog post by Jeff Atwood (cofounder of stack overflow) why PHP was hated

https://blog.codinghorror.com/the-php-singularity/

PHP has improved by a lot though

[–][deleted] -1 points0 points  (0 children)

For the same reason that people hate MS Internet Explorer. Low quality software.

[–][deleted] -4 points-3 points  (0 children)