What's the deal with downing PHP development?

I'm trying to wrap my head around why so many developers down PHP development like it is a second class language?

Secondly, what are the better alternatives for web development?

Did you find this post useful? Show some love!
DISCUSSION (76)

There are only two kinds of languages: the ones people complain about and the ones nobody uses

Python is just a toy language. Ruby is just for small scripts and not big applications. Java is verbose and overengineers simple things...

I could go on and on for any X language that has had mainstream following for the last few decades. People love to hate what's popular. If PHP 8 adds a solve_world_hunger() function, people will still hate it because why not.

EDIT: For those not familiar, the quote is from the creator of C++: Bjarne Stroustrup. Ain't that neat? :D

This.

All Turing-complete languages are isomorphic and all we are arguing about is a syntax. It’s like saying Spanish is better than German because, you know, German is too verbose and overengineers simple things...

I guess what people do mean, when they arge about the language, if more about quality of stdlib, community, high-level concepts available in language - lambdas, pattern matching, type system, that allows you to expeess solution better (it is to some extent a matter of taste, and preferences of your team)

lambdas, pattern matching, type system

It’s a fallacy that high-level concepts allow to express the solution better. Intelligence and experience of the developer do.

After first 5 languages one codes at professional level, the sixth and all the subsequent languages look nearly the same. Yeah, I wish there was pattern matching in ruby or dynamic typing in Haskell (yeah, throw your stones at me,) but I am fine with what language provides and I fit any paradigm while it’s still Turing-complete. Save for Brainfuck and Malbolge if the latter would ever reach Turing-completeness.

@okolbay I can get behind discussion on improvements / features of a language, but the OP stated about "downing PHP development like it's a secondhand language". That's not a topic that is built on level-headed reasoning and is something that will not garner fruitful responses either.

how comes you say its a fallacy and then immediately admit that languages lack features? )

after few programming languages mastered you can express nearly any solution with any of them, however, its the best tool that makes solution clear for your teammates, easy to maintain and adjust, and not the sole fact of being Turing complete

I think the impact of different syntax/grammar is much much bigger as in natural languages. Or could you easily express the same logic in assembler as in your favourite language. This should be very difficult and take much longer even if you really good in assembler.

@5n4p_ assembly is out of scope here as well as Egyptian cuneiform should be taken out of poetry writing contest.

All the modern languages are nearly the same. I switch between Elixir, Ruby, R, Python, and sometimes Haskell and Javascript without any issue. Yeah, paradigms differ, approaches differ, but until one tries to fight against the language paradigms and common approaches, but use them, all are nearly the same.

Have you also switched sometimes to PHP too? ;)

Maybe it differs more then you thought...

Nowadays I haven’t, but PHP is very similar to both python and ruby. Yes, I said that and I am positive that starting with 5.3 approx it is a very good language.

I must admit that my knowledge of PHP might be outdates (I haven't take a look on PHP for years). But if you once really dislike a language you rarely give it a second chance. Maybe that's one of the core reasons for the bad reputation of this language.

So, I guess you are most likely right and I'm most likely wrong about the PHP of today.

that's why Spanish is the second ( or even the first ) spoken language, while German is the first hated :)

Just yesterday, these two tweets got me soooo pumped to be working with Ruby on Rails

The future is bright and Ruby is every bit the small script language it always was. I'll be the first to say that Ruby is a weird language to have become such a staple for sprawling apps. But it's about so much more than the code. It's the ecosystems that spring up around it.

No programming language is great or bad in and of itself. Nothing exists in a bubble.

Being one of the people who did a good amount of PHP and still maintain existing projects (in my case, a couple of WordPress add-ons and a few websites), I think I can explain it:

When PHP arrived, it was grown into "a better Perl" for web developers. The first PHP versions were based on Perl and its syntax still reminds us of the time. That was before "web development" was a major thing - everyone wrote guestbooks and visitor counters, almost nobody wrote anything else. However, being one of few languages for that niche (that was long before some doofus thought that running JavaScript on a server would be a brilliant idea), it exploded - it transformed into a "business language for beginners" in an astoundingly short time. More and more features were packed into a "beginner-friendly" syntax, which, in turn, made more beginners (including me) choose PHP as their web language of choice. To please as many people as possible, abstractions were added, leading to incompatible varieties of the same feature. PHP 7 has, in fact, reduced the number of "official" MySQL bindings from 3 to 2 (mysqli and PDO) - which are still incompatible with each other. [But they improved the overall performance of the interpreter by a couple of magnitudes which is nice. Back to the topic!]

PHP itself is not a "bad language". PHP is forgiving though - it lets you mix HTML with PHP in the same file (similar to what ASP does), it is not strongly typed and you need to enforce strict syntax warnings if you want to have better code. At least two generations of beginners (the same people who probably would choose Python today) started their "career" with PHP code - that implicitly leads to a huge amount of bad PHP code available online, written by people who don't know better.

In my opinion, most people who talk badly about PHP should look into their own JavaScript projects. As if that would be a better language... :-)

what are the better alternatives for web development?

It depends. Generally, PHP is fine because (almost) every cheap web hoster lets you use it. If you absolutely want to avoid PHP because you are afraid of being beaten on the streets for that, here are my suggestions, based on personal experiences:

  1. Any language that can print stuff to the console is suitable for web development, you'll just have to compile your application and feed it to FastCGI. That includes C. Do you have a language you like for desktop development? Awesome. Use that!
  2. I generally recommend to use as few additional libraries as possible. But if you like third-party frameworks: Python has Flask (which is good enough for quick prototyping, at least), C++ has Crow (note: I have not tried that yet), Perl has Dancer. I'm sure that there are more.
  3. If you don't have an allergy against parentheses: Tried Lisp? Common Lisp has the Caveman2 and Radiance frameworks, Racket even comes with a built-in web framework.

I hope that inspires you a bit.

I seconded this until you’ve started to recommend Common Lisp as the first language for web development. C‘mon :)

I understand your intent and I myself had been starting with assembly language, FORTRAN and c. Starting with javascript somehow damages the ability to think logically consistent (maybe nowadays its effect is not as crucial.) Starting with the language that is well-grounded and backed by math rather than by wild guesses of language creators should be great, right?

Nope.

The thing is there are these two beasts: entry threshold and learning curve. Good developers are grown enjoying what they are doing. That leads to the greediness to learn, willingness to work and all that stuff that actually drives the growth.

Even Haskell has nowadays frameworks for web development. That does not mean one should start with Haskell (while it’s still better than CL for the beginners IMHO.)

I would recommend to start with something that allows to get a first result (yeah, awful, inconsistent piece-of-spaghetti-like result) in a matter of days. c, c++ and CL are beyond that.

My advise would be to start with something that has a gently sloping learning curve and is efficient. Python/Django, Ruby/Rails, PHP/Laravel, maybe Elixir/Phoenix. Create a blog engine. See how it’s exciting to have your own code running and showing pages.

Switch between languages until you get satisfied with the syntax etc. Until you feel comfortable writing code in it. I am lucky with ruby syntax, you might hate it and be joyful with python. That’s great!

The summing up. There is nothing wrong with PHP, as with all other Turing-complete languages. There might be something wrong with developers who do not learn and instead complain. Do not complain, try another language. You’ll find yours. Otherwise you’d better switch to management and/or sales.

Common Lisp is especially awesome for beginners. (It is not clear whether the OP is a beginner at all, by the way.) They don't need to adjust because every language is unusual to them. :)

“Do not do unto others as you would that they should do unto you. Their tastes may not be the same.”― George Bernard Shaw

Well, maybe. I am not talking about adjustments, I am talking about tastes. I did not need to adjust when I was 3yo, and still I like cucumbers and dislike tomatos.

PHP's a language people love to hate. It's messy, it's clunky, the standard library uses inconsistent nomenclature, it lends itself to a multitude of sins particularly in larger application architectures. It is often not taken seriously as a language, mostly for bad reasons, but the faults it does have do tend to make people who have used both PHP and other languages prefer those other languages to it (I among this number).

As with other things people love to hate its objective badness is often performatively overplayed. Eventually this becomes part of the legend, as it were, and people with no hands-on experience begin to immediately dismiss what worth it does have and what it's possible to accomplish with it. I hear PHP 7 fixed a lot of the real problems with previous versions, which is great, but I am also sure that this will do little short- and medium-term to stem the tide of PHP hate.

Modern web development is pick-your-poison. There's lots of interesting stuff happening with Node.js right now, to the point that the scene has become quite fragmented, but that process seems to be approaching stability as communities coalesce around a few major web and frontend frameworks. Ruby is also a substantial presence thanks to Rails' popularity, Elm is a thing, and there are of course still popular web frameworks in other languages like Python and Elixir. More server-centric web applications may still use a .Net or Java stack.

I get everything you say! I've made those same observations. I do like your point in which you said people who haven't even coded in it already dismiss it.

NodeJs is the new nice and shiny everyone is falling in love with. But ES5 currently doesn't even support classical OOP. So if the argument is that a language is fundamentally bad because it has faults, then why aren't languages like Javascript and NodeJS being looked at in the same light? Because they certainly do have their issues. Proven by the point that we needed to create Typescript.

But ES5 currently doesn't even support classical OOP.

I hate to break it to you, but many of us consider this a feature, not a bug.

If you value Composition over Inheritance then Javascript is for you. In any case I don't think it is fair to consider this a "fault", and many people (myself included) think that introducing class in ES5 was a big mistake.

This isn't to open a flame war about OOP vs. Functional programming. Just that if your language is good at functional programming, you should double down on that, rather than adding functionality for OOP-driven developers who don't understand why Javascript is a powerful functional language, and how to leverage that.

So you get people using classical inheritance patterns in a language that's meant for prototypal inheritance.

The thing with Javascript is, you have no real choice about using it on the front end. I think a lot of the server-side momentum is driven by this fact. The thinking being that a dev can leverage the knowledge that already have for the server side too.

I consider Javascript far worse than PHP (and I don't care for PHP that much after writing a lot of things in it). But that does not alter my lack of choice about whether to use Javascript. If I were coming at this thing fresh, I would be tempted to try to use the same non-optional language across the board too.

Many people don't take JavaScript seriously either thanks to its checkered history and common usage on the frontend. PHP is just lower on the totem pole.

For what it's worth, I consider prototypal inheritance and a lack of type safety reasons for using JavaScript. If I wanted classical OOP and static types, I'd use a language built around classical OOP and static types.

Interesting. What scenario would you say a developer might want a prototype model over plain-old OOP?

Many! Composability is a really powerful technique with a host of applications, and it's much, much easier to accomplish with a prototypal model than it is with classic object orientation.

For a concrete example, I maintain a data access library which introspects a database to build an API over it. A database contains tables, views, functions, and schemas. Tables can be read and written; views can be read; functions can be executed; schemas act as namespaces and contain objects of the other three types. The first three object types have certain attributes in common: a name, a schema they belong to, et cetera.

A classic OO approach would be to create an Entity class which centralizes the common attributes, and have each of Table, View, and Function inherit Entity. A method may act on any "real" database object (omitting schemas, which just contain things) as long as it takes an Entity and either only references Entity properties and methods or performs the appropriate checks and casts.

Then you get into the "building an API" stage. The goal is to return a Database tree that lets you issue a statement like db.things.stuff.find(), where things is a schema and stuff a table, determining the query target by navigating the tree. This isn't so hard: simply ensure that you create namespaces and attach Entities at the appropriate path.

However: the default schema is unnamespaced, so what happens when it also contains a table named things? What do you do now? Classic OOP has no easy answer. Do you create classes for TableWhichIsAlsoASchema and TableWhichIsAlsoAFunction and all the other possible collisions? Do you cross-contaminate your three base classes and gate alternative logic behind introspection checks? Good luck!

With prototypal inheritance, resolving these collisions isn't just possible, it's easy: just keep applying prototypes as they come in! If you already have a Table at a path which turns out to resolve to a schema as well, you can just hang the new stuff on the existing object. The only collisions that can't be resolved are due to (small-f) functions being overridden or becoming ambiguous, not due to simple pathing.

Ben Halpern DEV.TO FOUNDER

Hey there, we see you aren't signed in. (Yes you, the reader. This is a fake comment.)

Please consider creating an account on dev.to. It literally takes a few seconds and we'd appreciate the support so much. ❤️

Plus, no fake comments when you're signed in. 🙃

Because it is, for many reasons (most of them I blame on the community):

  • it isn't the best at anything (out of the mainstream languages)
  • didn't got the mainstream wave, so it was always the underdog
  • if it wasn't for wordpress and a few projects probably it was as popular as Perl now days, as in dead
  • the standard lib and the PHP as a project had bad decisions along the way and inconsistency
  • it is slow
  • a lot of messy code written in legacy projects
  • there is no PHP way to write things, even in this post comments people are not agreeing how to name variables. This leads to many other problems.

There are many reasons to not make it your first language:

  • because ..of the way things are now (low adoption), the number of jobs/projects is lower so is hard to find a good paying job
  • if you want to be a web dev is simpler and faster (to be productive and get a job) to learn only 1 language (JS) and to write front and back end
  • with Python or Java you have access to many more companies and projects and industries

With a 7 year experience on it (and I loved it for many years), after I have exit my bubble where PHP was everything I realized that it deserves to be a second class language and it doesn't worth to be added to a professional career skillset.

All of your points seemed to fit within the mold of what everyone else says bad about PHP. But I have not seen the statistics to prove the claims. Most people say it would be dead language as you made the same claim. How is it then, that it powers 88% of the web according to w3techs.com? w3techs.com/technologies/details/p...

In benchmark tests I agree it is slow. There are plenty of resources out there to prove that. However, I have been on many projects, where PHP out performed Java applications they had running in the same house. My own personal experience has been that If you build PHP correctly, you can get 15ms response times. Java out of the box gives me 100ms response times running none of my code.

There is not a direct correlation between "powering the net" (which can be said about bash and linux too) and how good PHP is as a language, the quality of the code and the number of jobs or its performance.

One guy that does not know PHP can take care of 100 WordPress and joomla websites with no sweats.

You can read the search for other statistics: most open positions, best payed positions, best cloud language, language popularity in 2018 and so on ..

well it doesnt have to be sudden death. but when golang and alike will become simple enough for entry-level devs to comprehend and amount of tutorials on how to launch your blog in go will grow, php will die away. along with RoR. and Python&Flask. Some mentioned that you can run php on a hosting. Its 2018 and spinning up few containers with stack of your choice was never easier, so this argument doesnt hold anymore.

also, looking at focus and rate of new libraries appearing for php, I predict it would miss next big thing with all these stream processing microservice setups.

after I have exit my bubble where PHP was everything I realized that it deserves to be a second class language and it doesn't worth to be added to a professional career skillset.

This. So many times this. One can think whatever comes to mind about PHP, but this bubble thing is especially hard to oversee.

I started my career with other languages than PHP. Basically I started with (Visual)Basic. Some C(++) during school(s). Started "real" programming with Delphi. From there the journey continued to some VB .NET and finally C# professionally.

For the web gigs involved I really enjoyed RoR for big projects and Django to some Degree. Even ASP.NET for corporate work is on the list. ASP.NET Core just feels like getting most of the rings right for now. But it mostly depends on the context of the project what the right choice of tool/framework is. Tried Phoenix (Elixir) for some toy project recently. FP is hard to grok if you come from OOP oriented school of thought, but the concepts and ideas make sense in a lot of places.

Due unforeseen circumstances PHP is currently part of my day to day work. And what should I say? I hate it. I always hated it and will probably always hat it.

Maybe you can write clean code with PHP. It is still dominant across the web. Unfortunately people still start new projects in PHP. But does that mean it does anything really well? It feels just mediocre every time you touch it. Eerytime. In any single place.

Anyway, I try to keep my mind open and try to find and accept the good parts of PHP.

But the most annoying thing is the ignorance of the people that live exclusively in their PHP bubble. They never saw anything else, but think PHP solves every problem the right way and try to convince you, that you are wrong criticizing things created by and in PHP. Don't get me wrong. I'm not generalizing all PHP folks. But I never experienced this bubble mindset in any other ecosystem as much as in the PHP bubble.

I can just propose everybody to look left and right and learn new ideas and concepts. Even if you're profession is and will stay PHP. But my bet is that if more people would do that, PHP would certainly loose it's dominance. Dominance of ignorance as I'd like to call it.

PHP was my primary (bread-winning) language for a long time. I think a large part of it comes from the quality of a lot of the PHP code out there. Also the ease-of entry means there are a lot of people writing code that is not very good, and so it perpetuates the notion.

However, you CAN write good PHP code. There are a lot of good developers writing a lot of good PHP applications. Still, there are probably many more developers out there writing bad PHP, so this reputation will probably carry on for a long time yet.

If performance is not a big concern, then PHP is a half-decent language these days. The only reason to really dislike the language itself would be just the sheer amount of bad code out there that exists and is being written (for whatever reasons, popularity, ease-of-entry, or the platforms/CMSs written in it... who knows?).

Secondly, what are the better alternatives for web development?

Elixir is my default language for web stuff these days unless I have a really good reason to not choose it.

Go interests me and I have friends who love it. I think it would be great in some cases.

People writing bad code is hardly a reason to hate a language. If that were the case, than by default we would be forced to hate all languages. It is something deeper than that I feel like. Maybe it's the fact that Devs, seem to overall, dislike and will look down on people who are just getting into coding? PHP is such an easy language to pick up so that's were a bunch of us start in web development. And maybe it also has to do with peer pressure somewhat? As if you tell another dev you are coding in PHP, you will automatically be looked down on.

Yet we discount the fact that 80% of websites are powered on PHP. We somehow discount the fact that PHP has seen the tool to generate the most income out of any other language in the world.

I don't really think most devs dislike beginners, but I could be wrong.

I honestly just think it's an outdated (but well-earned) reputation from when PHP was a messy procedural language being reinforced by all the bad code in the wild. And also it's "cool" to hate on PHP.

Many devs seem to dislike non English speakers, including a lot of php devs. As long as php is used heavily by the rest of the world, even after their code quality improves, people will hate on them and their chosen language.

However, you CAN write good PHP code. There are a lot of good developers writing a lot of good PHP applications. Still, there are probably many more developers out there writing bad PHP...

I see this argument in most threads when PHP is discussed. IMO you can switch pretty much any mainstream programming language in PHP's place and this will still hold true.

That's true, but I am certain that PHP destroys all the others in ratio and just plain ole massive volume.

They say PHP is behind 80% of the web and that scares me... and I like PHP.

I think one of the reasons why Elixir is not more popular is its lack of support by popular Paas offers on cloud services. Lobby to fix that and you have a bigger community instantly :D

For example Elixir is not present in the list of default languages for Heroku - heroku.com/languages - (yes, you can use custom buildpacks but you don't have the company support) nor in Elastic Beanstalk's - aws.amazon.com/elasticbeanstalk/faqs/ - nor in Google App Engine's - cloud.google.com/appengine/kb/ - nor in Azure App Service - docs.microsoft.com/en-us/azure/app...

None of this has anything to do with the language, just needs a little support by the major vendors...

check out this - eev.ee/blog/2012/04/09/php-a-fract...

some of it is not valid anymore, but gives you perspective, from where and from which mindset php is coming. And even though latest version might report another performance boost, and opcache became usable in cli commands (basically any non-web background processes) there is no php webserver - it relies on nginx, so no gRPC server, for example. As well as almost nothing from background processing or reactive/async patterns are available (kafka connectivity for example). PHP is still fine for Drupal/Wordpress, but if you are starting your own project, its very likely that sooner or later you would need something more than templating engine (which php at its core essentially is))), and here you will be dissapointed by what this platform can bring to the table.

As alternatives for web-based projects I would name Ruby + Rails or Python and Flask, if you want to start fast, and virtually any all-purpose stack, if you are fine with learning it first (its extremely simple to start with ror or python, but this should not make you think its easy to handle complicated design descisions)

The first two lines of the blog told me everything I need to know about writer... "I’m cranky. I complain about a lot of things." This hardly seems like an unbiased approach to reviewing a language.

Your main point about it relying on a web server. I think most languages do and don't come bundled with one. Java (a very popular web language) relies on an external web server as well.

its a pity that first two lines draw you away from a darn good writeup. anyway, my point was more about php not being able to run its own production-grade webserver, rather than having or not having built-in one per se

Here are just a handful of reasons why PHP is generally regarded as a badly designed language:

Needless to say, PHP has its own advantages which makes it very easy to get a simple webpage up and running with little hassle - it mixes with HTML very well and its dynamic weak typing system doesn't "get in the way" unlike, say, Java (at least from the eyes of a total beginner). However, as one digs deeper into PHP, one will begin to find numerous inconsistencies in every aspect of the language - the inconsistent naming system of built-in PHP functions (e.g. the inverse function of htmlentities() is html_entity_decode()); the inconsistent naming conventions employed between different built-in PHP classes (e.g. classes related to reflection using camelCase for method names while those in the mysqli class using snake_case for method names) ... In simple use cases such as a personal webpage, such inconsistencies rarely cause an inconvenience but when you start building larger projects such as a corporate website, such inconsistencies start to become obvious which reduces the productivity of the programmer and makes unexpected bugs more likely (unless you already know PHP inside out).

What IDE are you using that doesn't autocomplete htm* ???

Similar problem exists when a library for one task was written by a camelcase fan and another by a snake case fan but I need to use both in 1 script.

But it's not a problem when the IDE can autocomplete.

Autocomplete may help you write code faster and reduce the burden of memorizing method names (for example) but it still doesn't change the fact that other developers will probably require slightly more effort reviewing/understanding your code just because there is a random mix of camelCase and snake_case.

The most likely person to review my php code is someone who also knows php.

And if I'm using a library whose author preferred camel case along with another library whose author preferred snake case, the problem still exists independent of PHP's inconsistencies.

So that being said. If you decide to open a business doing some type of software development. What is your choice?

Probably Python or C#. Depending on the type of software I intend to develop, C++ (or even C) is not out of the question either. Or I could just stick with JavaScript (it's got its own problems as well but at least has a wider range of applications than PHP) :p

Haven't posted here for a while, but obviously topic close to my heart, so here goes.

Languages and frameworks are like religions - in the end they all do the same thing, yet the language one person uses is absolute single one everyone else should use, and every other option is bad, dying, dead, etc.

As with any language, if things get tough, you find a solution. Maybe different algorithm works better for given problem? Maybe you need to change server setup a little bit?

While these discussions still add to generic self doubt and impostor syndrome, I wouldn't pay too much attention on what other developers say, especially the ones that admit they don't use the current version of the language - they have their own reasons to prove that they do not need to use PHP, and that has nothing to do with you or your projects.

However, the problem rises when non-technical people start to request language or framework changes purely based on trends or articles on tech blogs that are close to click-bitey.

But as long as you keep your clients happy, no matter what tech you build your projects on, that's the only thing you need to worry about, IMHO.

You can write good, well-designed code in any language. Working in a good,
well-designed, PHP codebase is probably as pleasant an experience as working
in a good codebase in Javascript, Ruby, or Python. I would rather write in
a good PHP codebase than in a bad Javascript, Ruby, or Python codebase.

However I believe:

  1. Unhealthy PHP codebases are more painful than unhealthy codebases in other languages
  2. You have to fight harder against PHP to keep your codebase healthy than against other languages.

For these reasons, I would strongly recommend against PHP for new programmers and new projects.

I'll provide a couple concrete examples of how I have experienced this:

a) Testing with mocks is difficult because you can't monkey-patch in PHP.

I've had a lot of difficulty writing unit tests for PHP code that wasn't designed
with unit testing in mind. In order to write a good unit test, you need to mock
out your database calls, but that can be really tricky if you are calling methods
that were not designed to injecting mocks them easy.

In Javascript, this is not as much of a problem because you can literally monkey-patch
anything. Here's an example:

const db = require('./db')
async function banUser (id) {
    const results = await db.query(
        'SELECT ip_address ' +
        'FROM users ' +
        'WHERE id = ?',
        [ id ]
    )

    const ip = results[0].ip_address
    return await db.query(
        'INSERT INTO banned_ips VALUES (?)',
        [ip]
    )
}

async function testBanUser () {

    // Store the original definition of `query`
    const $query = db.query
    let calls = []
    // Monkey patch `query`
    db.query = async function (statement, values) {
        calls.push({ statement, values })
        db.query = async function (statement, values) {
            calls.push({ statement, values })
        }
        return [{ ip_address : '100.100.100.100' }]
    }
    await banUser(2)
    // Restore the original definition
    db.query = $query
    expect(calls[0]).to.deep.equal({
        statement: 'SELECT ip_address FROM users WHERE id = ?',
        values: [2]
    })
    expect(calls[1]).to.deep.equal({
        statement: 'INSERT INTO banned_ips VALUES (?)',
        values: ['100.100.100.100']
    })
}

The "monkey patching it with a mock that when called replaces itself with
a different mock" is kind of ugly, but it works and you can do it much more
cleanly with a library like "sinon.js" -- an incredible library.

In PHP, trying to monkey patch like this just fails. If you do something like

function testBanUser() {
  $database->query = function ($statements, $values) {
     echo "Joke's on you! You can't monkey-patch in PHP!";
  };
}

and then call $database->query, it will still just end up invoking the
original definition.

There's a PHP library called "mockery" that can get you a little further than
this, and gives you tools to inject your mocks in certain cases. But it's complicated.
Mocking static methods gets especially hairy, and mocking final methods is
nigh impossible. Overall you just really, really have to fight for it.

b) Another example of how PHP actively leads the user into writing bad
code
is superglobals. If you want information about the HTTP request you
are currently serving, PHP's default way of exposing this information to you
is through the $_REQUEST superglobal. As experienced programmers know,
global variables are a code smell, and they rapidly lead to unmaintainable
code. In a healthy codebase, you should encapsulate the superglobals, access
them only in one place, define some sort of wrapper object around them to
control access to HTTP request data, and pass such objects as arguments to
the functions/methods that need to access/operate on http request data. It's
possible to do this sort of thing in PHP, but the language makes it
difficult. The language itself is basically actively encouraging you to do
the wrong thing and use these superglobals everywhere.

Node.js does the right thing here. You instantiate the HTTP server yourself
and you create handlers for HTTP requests that take HTTP requests object
in as parameters. No global variables necessary.

These are just two examples -- I could go on and on and write more, but I
believe they speak to a general theme. It's possible to write good PHP --
if you know what you're doing and have a good design sense. But PHP the
language and PHP the ecosystem is going to be fighting you every
step of the way.

PHP is the only language where I have seen development practices that are mind blowingly awful. I fully understand that you can write bad code in any language, but for some reason PHP devs manage to top any expectation of bad code one could have.

Let me give you 3 examples.

  1. The switch statement (or equivalent) is available in many languages. It is fine to use. The paradigm is that you switch on a variable and each case is a constant. There are two languages I am aware of that do not enforce that constraint. javascript and PHP. There is only one language I have seen this constraint ignored. PHP. In multiple places in the code they used switch(true) and the case statements called functions. This was a well known company.

  2. Using comments as code. I was trying to use a CMS developed in house (different company to the one above, not well known) and I was trying to figure out how to change which the main page was. I had to change part of a comment. I realise this isn't a default part of the language, so I guess the dev must have felt really proud of themselves.

  3. Drupal 7 breaks PHP's raison d'etre. In my opinion PHP is a templating language for HTML. That's the best you can hope for it. Drupal 7 (maybe 8 is better, I don't know, I ran from PHP after this) is clunky, slow and confusing. But on top of that we had installed three themes, two were deactivated. Yet somehow a deactivated theme was able to interact with the active theme and break the templating it provided. Amazing. Why would Drupal allow deactivated themes to do that?

So, sure, you get bad programmers everywhere, but the frequency and severity which they occur in PHP means I am never going near it again. It is a bad language.

As an alternative, I find Django a lot easier to get into and use than Drupal.

Let me start with a blatant opinion: I'd rather use PHP than pre-await Node for writing a web application, because callback-oriented development is stupid. Node only became worth using when they added async-await, and even with that you end up having to write wrappers for outdated parts of the standard library just to write straightforward code. JavaScript just isn't that good of a programming language anyway.

Now with that out of the way, PHP has two big problems:

  • It's inconsistent. Like, blatantly inconsistent, for no obvious reason. Some functions have prefixes like array_map($arr, $fn), some of them don't like sort($arr), some of them are not actually functions like empty($arr), and PHP has method call syntax, but doesn't use it for any of the array stuff. And parts of the standard library use CamelCase, while others use snake_case. The classes stdClass and DateTime are both in the standard library, too, just in case you were wondering what type of case class names should use.

    • Because of this, WordPress and Laravel both have equal claim to being "the PHP way" despite having such different coding styles. The better-respected Python, for example, has "there should ideally be one clearly correct way to do it" in its core manifesto.
    • Even other old crufty programming languages, like Java and C, are still able to at least follow consistent naming schemes (C always uses snake_case, Java has lowerSnakeCase variables and methods and UpperCamelCase classes).

  • It has built-in affordances that are unusable in large, well-tested codebases. Superglobals, for example, make any functions that use them much harder to test, and php.ini is just one more piece of the environment that can affect whether a piece of code works right or not. And when PHP starts writing warning messages to the browser that get interleaved with the rest of your HTML, stuff can get really, really broken, so you have to turn that off, too, in production.

    • The last big PHP app I worked on had a bunch of wrappers to try to work around this, and shipped a "use this php.ini" in the source repo for the same reason.

I would like to start by saying that people love to hate. To me it’s almost a fact, anything
widely use by people will be criticized, always has been always will be. So even though I’d like to think myself different, there might be a little bit of that in my “hate” of PHP. In truth as long as I’m not forced to do PHP, I do not care what people code with. There are far worst issue existing in our industry today like the lack of professionalism or security concerns in project today…

I try to be short about why I’m downing PHP.

First : everything written here was true at the time and nothing of significance happens that change the core issue that this article presents : PHP is badly designed. This has the effect that you have to possess deep knowledge of PHP to build solid and maintainable solutions. Not knowing those quirks will put your project in some sort of issues at some point.

Second : there are better options everywhere .NET platform, Java platform or even Node (which I also dislike) just to talk about major one. Now that one is a bit tricky to explains but I’ll give it a go.
PHP has the cheapest cost of hosting that I know, also you do not require a dedicated host to make it run efficiently, to a lot of business out there, this matters most. I understand and respect that, I just also remember that businesses also loved IE6 meaning business is king, it’s not always working in its best interest …
So when I say “better”, I am talking about the famous “cost/benefits” ratio from a technical and business point of view and here what I mean to say : there are no more benefits to PHP than its hosting cost for making websites comparing to its concurrents. On any other aspect, every major web platform does what PHP does while the reverse is often false. What’s worst is that while PHP specialize in web development, it never has the best solution.
I am not even going to talk about distributed applications or web services since parallel processing, concurrency or asynchronism are just not what PHP does (no need to go further for me).

Third : PHP 6 never got out and nothing on PHP 7 makes HHVM and Hack obsolete in fact, I often wonder why PHP 7 at all ?? Many reasons for PHP 6 failure, some technical other not but assure you it was not the skills of the people involved those people are seriously good developers.
What matters to me, though is : that there was technical reasons. Check them out...

Fourth : PHP does not scale and no amount of good practices can change that. Try writing a website in assembly with good practices
For that one the Facebook example shows it best I think. They are not happy at all with PHP.

Just to get certain things out of the way :

  • Yes PHP has great qualities: it’s a really productive language, clean state at each request, the perfect fit with the HTTP 1 model … but they are far from enough for large projects, its defaults far outweighed its qualities.
  • Yes for small to medium websites it does not matter if you use PHP or not, but to be able to grow and maintain a codebase, is one of the core part of a developer’s job and PHP as a language does not help you. Which is my point.
  • Yes Javascript on the backend side is not a good idea (at least I think so) but it’s still better than PHP because the tooling is better, Node is fully asynchronous , DevOps is mature for that platform and everything transpiles to JS.
  • Yes PHP 7 makes things better. So what ? PHP 4 and 5 did the same at their times, didn’t change that it’s badly designed then, doesn’t change it now …

All that being said I am against all bogus and dumb statement like « PHP is not a programming languages » or « PHP developers are not real developers ». You can write software in PHP and it works (Wordpress, Slack …) but all platforms are not equivalent, that’s just false IMHO, ** that’s why I’m downing PHP development**

On the better alternative depends what you’re up to ? SPA or not ?

To be clear php 7 is pretty good, but here’s some reasons why php is used to be hated
It’s poor support for OOP paradigm , wierd syntax also some build-in functions had unexpected behavior in some cases.

I'm trying to wrap my head around why so many developers down PHP development like it is a second class language?

There are a lot of people that explains why so I am not going to repeat it again.

However, if you are just doing PHP on a low scale or have an API on low scaled PHP could be an amazing tool. On a large scale website/API, PHP might be hard to manage. In addition, a lot of popular CMS/frameworks written in PHP they focus more on having nice tools and performance is not the main priority.

Secondly, what are the better alternatives for web development?

PHP is great for web development; however, if you are trying to do any type of heavy back-end process PHP might not be the best option for it. I would not recommend NodeJS either for other reason than I am not going to get today.

If you need to do any type of heavy processing, I will recommend Go, Scala or Java.

Sadly, is just a meme that became a popular opinion and the arguments for it are so bad that applies to every language.

In addition to previous comment I would also point out a few things that everyone hates writing php:

  • you need $ anytime you call a variable.
  • you need 2 chars for method calls "->" or "::".
  • at a certain point in your life you'd probably need to know in advance the type of your variables
  • there is a crappy function or library somewhere in your code that might give someone full access to your machine
  • using OO elements along with functions its just confusing, most of the times classed are merely collections of functions with no coherence.

I disagree with the assumption that "everyone" would hate that.

  • $ for variables: yup, so you can see instantly that it is a variable and not a function, a constant or a keyword.
  • type of variables: just prefix them, like you would in JavaScript, Python et cetera.
  • crappy libraries: easy solution, stop using other people's code. :-) That said, if someone can get full access to your machine, you should fire your admin. PHP should not run as root.

The other points: I agree.

@tux0r Imo, don't prefix, don't use hungarian notation.

If we get typed properties in PHP 7.4 (or any later version) there's very little ground to cover that isn't typed.

Using type hints everywhere with declare(strict_types=1) fixes a lot of these issues.

@lucafabbri

  • I like the two different method call notations. Clear separation of calls to static methods and instance methods.

  • Not sure what you're driving here, but if someone can't do OO design then what can i say? If you're talking about global functions like in_array() then i agree. Yes they are bad. But frankly, do they really differ that much from static method calls like Array.map() or Math.max()?

Let's say that you are new to PHP and you are bugfixing someone else code. There is a lot of overhead understanding what belongs to global, to user functions and classes. This is not clean. While a class in other languages specifies all namespace in its header, in php you can come to a fall of includes that you need to drive back until you find where the function is. Namespace are actually more clean, easy to debug and extending.

Ah, now i see. Yes, this is incredibly bad practice.

PSR-4 autoloading with Composer is really the only sensible way to deal with imports. There should only be a couple of script files in a project that are not classes. Maybe some bootstrapping script if vendor/autoload.php doesn't cut it and a front controller. Most frameworks also ship some sort of console script to run different commands. That should be enough.

There should be no need for require()s or include()s in other parts of the application.

There is also type hinting available on method boundaries too, if that's an important feature to you.

Of course, there's nothing stopping you from using a variable as a function name and then calling it.

you need $ anytime you call a variable.
you need 2 chars for method calls "->" or "::".

seriously...?

I'm not sure if you're replying because you think it's a weak argument against PHP or if it's because you're incredulous that you need such things.

Just make the some project in PHP, in C#, Java and Node.JS and let us know

I was thinking the same thing. I heard many JS devs saying the same thing.

I'm one of the PHP haters :) This post is able to express the problems I see with PHP much better than I can: eev.ee/blog/2012/04/09/php-a-fract...

Yeah this one was shared already. My response was basically the beginning states that the author is “cranky.” Which lended itself to mean this blog post is basically bias. In order to make an argument, you have to remain unbiased. After all the comments to this question, I still don’t have a clear answer other than people just don’t like it. And there are many reasons they don’t like it.

Maybe it's the oppression complex?

I kid, somewhat, but this is really a loaded/quora question.

It seems like it just has a bad rep because it does. Devs are seeming to find their own reasons to fill the gap on why. None of which have any compelling reason behind them. I think what I've learned from the response here is that PHP is not inherently bad.

One great leader I've met asked me once, "...well how much money has PHP made over the years as a whole?". He went on to explain "...that's its true value."

That will be the way I look at it. As a business tool. Not a dev tool.

Because PHP has no focus.

It doesn't excel in any aspect of a programming language.

It's not the fastest, the safest, the more consistent, the easier to learn, the more expressive, the more syntactic sugary, the most concise, the more human, the less human, the more concurrent. It's just there.

When someone programs in PHP, it's almost like "I started with it when I was beggining and well, I still code on it and that's all". You simply don't have any good reason to pick PHP from languages that we have available on the present.

PS: I don't wanna offend anyone tho, just wanna answer the question.

I guess PHP focus is in the frameworks. There are a lot very easily frameworks that solve so many things in PHP than in other languages is not as standardized and/or easy to use.

Classic DEV Post from Jul 13

What Do You Look For in a Mentor?

A discussion around empathetic & helpful tactics for teaching brand new developers

READ POST
Follow @kim_hart to see more of their posts in your feed.
Joshua Johnson
a developer looking to share cool things.
Trending on dev.to
Let's talk about the new CoC for Linux
#discuss #linux #opensource
Golang, it was love at first sight.
#webdev #go #productivity #learning
Thoughts on Dashboard Design
#data #dashboard #dataanalysis #productivity
Lessons I learned from training with special forces that I use in software development
#beginners #career #motivation #dieliving
Software People — How Do You Deal With Stress/Bullies/Frustration?
#life #software #stress #discuss
How long have you been programming?
#discuss
What was your first PR on Github?
#github #discuss #programming
Why I Turned Down a Job Opportunity
#career #perspective