I made a tongue-in-cheek comment in another question thread calling PHP a terrible language and it got down-voted like crazy. Apparently there are lots of people here who love PHP.
So I'm genuinely curious. What am I missing? What makes PHP a good language?
Here are my reasons for disliking it:
PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
PHP has inconsistent parameter ordering of built-in functions, eg array_map vs. array_filter which is annoying in the simple cases and raises all sorts of unexpected behaviour or worse.
The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.
A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!
Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.
PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.
Worst of all, PHP convinces people that designing web applications is easy. And it does indeed make much of the effort involved much easier. But the fact is, designing a web application that is both secure and efficient is a very difficult task.
By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design. It's given them access to capabilities that they lack the understanding to use safely. This has led to PHP's reputation as being insecure.
(However, I will readily admit that PHP is no more or less secure than any other web programming language.)
What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.
So convince me otherwise!
I'll take a stab at responding to each of your bullet points
PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
I both love and hate this topic. Because at its core, this issue is correct. Why are some bi-word function split with an underscore, and some aren't? Why do needle and haystack parameters swap positions in the argument signature sometimes? It's ridiculous. But at the end of the day... does this really matter? My IDE with intellisense and php.net just a browser click away, this is just plain not that big of a deal. Is it a negative against PHP as a language? Yes. Does it hinder my ability to be an effective programmer? No.
The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.
Personally, I think this is not a good point. Deprecation is necessary to the evolution of a language, especially one that has as much kruft as PHP does. PHP gets a lot of flak for "making it easy to be a bad programmer*" but at the same time, the PHP group also gets in trouble when they try to remove stupid constructs from the language, such as call-time pass-by-reference. Eliminating call-time pass-by-reference was one of the best moves they ever made. There was no easier way for a novice developer to shoot themselves in the foot than with this "feature".
A lack of consideration in redesign. The above deprecation eliminated the ability to, in many cases, provide default keyword values for functions. They fixed this in PHP 5, but they deprecated the pass-by-reference in PHP 4!
I don't think there's a general lack of consideration at all, I think you just got stung by this particular change and have been left with a sour taste in your mouth. Language changes are often known months if not years ahead of time. A migration guide was provided for the move from 4 to 5, and the version differences are documented in the manual. Call-time pass-by-reference was a horrible "feature" and doesn't give the developer any expressive power they can't get by other means. I'm glad it is gone (along with other crap like magic quotes)
Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
I have mixed feelings about this. Part of me thinks "who cares, character escaping has no meaning outside of a string anyway", and part of me thinks "surely they could use something better". But could they? I don't know, I'm not a developer for the Zend parser. Is it a huge oversight that until 5.3 PHP never had namespaces at all? Yes, absolutely.
Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
I think it's ok to disagree with how PHP does this, but disagree that it makes the language "bad". But ask me how much I want to sit in this topic and argue about weak vs strong typing. (P.S. I don't, at all) For the record: PHP will issue an E_WARNING level error when the type of an argument matters and cannot by solved by coercion.
Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
PHP is a DSL for the web. I've been doing it full-time for 8 years and have maybe used recursion 4 or 5 times, usually for some type of annoying directory or XML traversal. It's just not a pattern that is needed for web development that often. I'm not excusing the slow performance, but this is an academic issue far more than it is a production issue. If you need really powerful recursive performance, PHP is already the wrong language for you.
Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
I totally 100% agree with this.
PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.
*Hmmm, this topic sounds desperately familiar...
But seriously, I find it remarkable that people will complain about a language that will absolutely 100% let you implement any output system you want (the sheer volume and style of PHP templating systems alone speaks to this) - OR - skip all that overhead and just output directly. This does not make PHP bad at all. It's part of what makes PHP good.
PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.
Do you mean bytecode caching (like an accelerator), or output caching?
If the former, then I don't really know how much I care about this topic. Accelerators are free and easy to run. We could argue about why it isn't part of the language but in the end, I don't think it matters much.
If you are talking about output caching then I don't know what to say to you. ANY web project with significant traffic needs caching (seed podcast #27, for example). This is not a PHP-specific issue at all.
In summary, I think you consider PHP a "bad" language in a very academic fashion. And in your previous post you were probably voted down by people like me who use PHP to "get things done".
All your criticisms (and some more) are valid. You are allowed and even expected to hate PHP.
But, then again, it has some benefits:
Finally, you can overcome many if not all the downsides by writing good code you'd write in any other language. You can write solid, secure and good smelling code in PHP, which many times will run faster and be easier to host and to scale than many alternatives.
What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language that's spawning poor programmers.
Simple. The fact that poor programmers get very defensive about their language. ;) PHP is easy to learn, much easier than the alternatives, and once you've learned it, it's not exactly obvious 1) what's wrong with PHP, 2) how the alternatives are better, and 3) how to switch to, and learn, one of the alternatives.
And perhaps the fact that, well, what alternatives do people have? ASP? That has plenty of problems on its own, from being unable to run on the majority of webservers (Apache), to some ridiculous and overengineered design choices on its own (webforms? Viewstate? AJAX where your asynchronous" requests are intercepted and run sequentially?) Ruby on Rails? Well, perhaps, except how many webservers support it again? It's not exactly easily approachable at the moment. And it's slow. So perhaps PHP's "strength" is really that no good alternative exists. At least this is why I stay away from all web programming when at all possible. PHP sucks, and I'm not too keen on any of the alternatives either.
PHP has so many fundamental problems that it's not even funny. From the lack of unicode support, to the many implicit type conversions which often lead to unexpected security holes, to the complete mixing of presentation and... everything else, or to the default database module which doesn't (last I checked) use parametrized queries. We're talking about a language made for two things, database access and generating HTML, and which is terrible at both.
It's just a nasty mess, a language designed by people who aren't qualified, or able, to design a language. ;)
In addition to the above, PHP's documentation is very good. http://www.php.net/rand and you go right to the documentation page for it, as well as tons of user contributed notes.
PHP is by no means perfect, but it does get the job done and its class system is better than some of the competition.
Ok, let's use a nice car analogy to understand the complete pointlessness of this discussion:
Title: Defend cars, prove me they aren't horrible.
Ok, I think you get it.
So... with all this against them, all this long, harmful, unattended, stupid and nonsensical development in this tool, how the heck is it so popular?
Probably because you wouldn't use a bathtub to get you from point A to point B. (The point is having a tool for each job)
Probably because, even if quite full of problems, it's easy to use and is the one with the most support. (Repair shop at every corner, wide spread means of refueling)
Probably because there is a very low entry barrier to hop on board.
Either that or, like Asterix always says: "These Romans must be mad!"
Wouldn't you agree?
PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
Yes, this is annoying. However, anyone who's doing serious development in PHP is going to have them memorised quickly, and what's not memorised is very easily found in PHP's online documentation. I don't feel that this inconsistency slows me down at all.
The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.
Only if they upgrade unwisely. PHP4 didn't end-of-lifed until three years after PHP*5* was released. Three years to transition to a new version is plenty of time to fix things like that, and deprecating crappy ways of doing things is important to the rational evolution of a language.
Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
Backslash is used universally for escaping within strings. It has no meaning outside of one. Again, this is the sort of criticism that is meaningless after a few days using the language.
Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
I can state categorically that I have never, ever had a problem caused by accidentally turning an array into an integer.
Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
Can't personally speak to that - I haven't seen or performed benchmarks. I don't use recursion much at all, though.
Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
PHP'll throw an error if you try to redefine an existing function, so what's the risk here? What ambiguity is introduced here - can you offer any concrete examples?
PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.
One can write crappy code in C++ or Java, too. I find the ability to do this a positive feature of PHP, too - if I were to choose a programming language to teach a six year old basic programming, it'd probably be PHP. Yes, the ability for anyone to pick up some PHP has led to a lot of bad code out there, but I consider more people having the opportunity to learn to code a good thing.
PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.
Your last, and least compelling. So what? There are a variety of non-commercial caching products for PHP. You have options, and there's no reason the maintainers of PHP shouldn't be allowed to try to profit off their expertise. You're best off paying for a Windows and Visual Studio license to develop in .NET, but no one rational bashes the platform based on that.
These are not your reasons for disliking PHP. These are your excuses for not even giving it a chance.
I think before you can be convinced that PHP is a language worth keeping around, you need to recognise that the objections you have to it are just not obstacles to people who use it everyday.
At it's core, you have a language that provides an execution environment that is easy to setup and easy to begin to use. The language itself is highly orthogonal, which makes learning it easy. It does not come with a framework That You Must Use, or and IDE that is essential. It does not have a separate compile step. All this means you have a language that does what it does and gets out of the way. For programmers, this provides an almost blank sheet of paper to go off in whatever direction they choose to build what they need to build. The language is flexible enough that there is often a variety of ways to achieve the end-result, some better than others, but others are just one amongst equals. PHP makes things like strings and hash-tables first-class objects and provides a generous array of tools to manipulate them. There is a wide-range of built-in libraries and there is a wealth of third-party code to supplement this. In addition, it has all the tools and features to scale to massive massive websites on huge databases.
Some of its current problems are as a result of the language being forced to "grow up" as thousands (if not millions) of developers make it do things the designers never even thought of, let alone thought possible. Fixing these requires a slow and careful migration so that you pull along the bulk of the developers. Notice that it took some effort to get people off PHP v3 in the last two years - and v6 is just around the corner!
It is possible to write high quality code in PHP, with clean interfaces, good separation of logic and so on. The problem is that the average quality of PHP programmer does not reach that high. And you can't force them to be better -- because that simply doesn't work. They have to learn how themselves. If they are capable of learning. I've seen PHP programmers who are just incapable of getting beyond their current mediocre level.
PHP has a lot of warts, but it is effective and widespread. Just don't get hung up on what it does 'wrong' -- most PHP programmers don't and don't need to.
Any tool, in the hands of an amateur, can become dangerous. So I wouldn't blame PHP for what people do or don't do with it, despite its apparent flaws.
PHP can be used to develop secure and robust web apps that are just as well designed as anything written in .NET, as long as you know what you're doing.
Perhaps the equally relevant question to ask is what language would you consider superior?
In my office we use PHP because of the low overhead in getting started with it because we use a LAMPP stack where everything FOSS. Running on a Microsoft platform would run my company into the ground. So I guess one valid reason that companies go with PHP is because its FOSS.
The other reason that I've seen others point out is that it gets used by many individuals for their own personal projects, and as a way for them to enter the world of web programming. I personally don't see anything wrong this. Everyone has to start somewhere, and no one is born writing beautiful code. Its something that we all grow into.
I think that other languages discourage what you might classify as bad practices by their very nature which is something that PHP doesn't do very well, but I wouldn't discount the language out of hand.
The bottom line is that PHP is (like every other language) nothing but a tool. Every job has a tool that suits it. PHP is greatly suited for quick, agile tasks that need to be done NOW.
In the real world, unfortunately, managers run the show. If a client needs a contact form, I can bang that out in 30 minutes using PHP (and even design it "properly" using an MVC architecture). Or, if I was a novice (and I say that in a loving way), I could wite the same form using ugly code, that works just as well.
Now, I started hating PHP after using it for several years for a few of the reasons listed above. Mostly, I disliked it's OOP implementation and hated the fact it was case insensitive.
As I look back on it though, I think the major problem isn't the language, but inexperienced programmers who are hired to write in it. It's the "cleaning up spilt milk" problem. About 90% of the legacy PHP code I've had to alter or maintain has been TERRIBLY written. It's not the languages fault, it's the inexperienced (or lazy) coder's fault. They took the hammer (PHP), and instead of simply driving a nail into a wall with it, they cooked spaghetti with it (successfully).
These days, I have been writing code in VBScript and Perl (NOT by choice, but gotta make a living). After working with those two nonsensical and disheveled languages, it really put PHP into perspective for me. I MISS PHP. I didn't realize what I had till I lost it. Ever try to get the size of an array stored in a hash reference in Perl? I did. Took 2 hours and I didn't solve the problem. I was forced to do a hack. In PHP, I'd simply use count() and TA DAH! There is the size of the array (which is actually a hash in PHP but that's out of the scope of what I'm trying to say).
Does the language need improvements? Yes. Does the language have a poor governing body? Yes. But what are it's strong points? It's pretty simple:
So in reality, It's not the language itself that's absolutely terrible, but the ironic fact that it was designed to be so quick and dirty to develop with, that it attracts poor programmers with poor programming practices.
It's ease of use is a double edged sword. It allows you to quickly write good code, just as easily as it allows you to quickly write bad code. So don't blame the gun, blame the guy who pulled the trigger.
But I'll tell ya one thing, If I had a choice between writing a web app in Perl through CGI, or using PHP; I'd use PHP in a HEARTBEAT.
PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
PHP exposes the function signatures of all the low-level libraries that it uses. Do you make this same complaint about C or C++? You should because those are the same function calls and libraries. You have the freedom to develop whatever abstractions you want over top of these low-level calls -- you aren't limited a specific high-level toolkit.
The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions.
They depreciated call time pass-by-reference which no other language has ever had. Regular pass-by-reference still exists and always will. I feel bad for the PHP developers, they try and improve the language and still get dumped on because some people don't know how to read.
Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
Agreed. But that pain hasn't even been released yet. Lets hope they change their mind. If anything, this particular issue has got me looking into alternative languages. But I have a lot good object-oriented code written in PHP that it's hard to change.
Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
I've got hundreds of thousands of lines of code in PHP and I don't find the implicit conversions to be a problem. It will not happily attempt to magically convert an array to an integer (unless you explicitly cast it).
Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
I'll give you this one; but if you're written complex algorithms in PHP then you're using the wrong tool -- plain and simple. PHP scripts aren't designed to run for long periods (in fact, the shorter the better for responsiveness). This is like complaining that you SUV uses to much gas or your Smartcar doesn't have enough room for 2x4's.
Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
They are case-insensitive because HTML tags were, at one time, case-insensitive. But your argument is stupid. If functions are case-sensitive, you're still introducing ambiguity: now you have a function named bob() and Bob() that do two entirely different things. In PHP, that sort of madness isn't allowed. If you want consistency in naming, be consistent. PHP doesn't stop you.
PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.
This is entirely wrong. It does not practically require coupling processing and presentation. I've been coding in PHP for decades and while I did start by making them together (everybody did -- I came from classic ASP which does the same thing).
I think of PHP's functionality in this regard as the same as Python's immediate mode. You can fire up Python in a shell and just start typing commands and getting results. PHP is a web based languages, so this is it's equivalent of that functionality. When I need to quickly test something, I can bang out a quick script instantly and don't require bringing in a big framework (as I would with any other language) to get a result.
PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.
Abysmal? Please. Take your exaggerations elsewhere. PHP is plenty fast enough without caching for 99% of what it's used for. For that remaining 1%, there are plenty of free code caches available (I use e-accelerator) and it will be included as standard in PHP6.
Are we done with this tired topic now?
If you have a problem in your application, you can always find someone nearby that knows PHP.
The huge pile of
But for the language itself, it's sort of dynamic with decent performance? (best I can do, sorry PHP)
I wouldn't say PHP is a bad language, but an ugly language. There are many impoverishing things about it compared to other languages.
Inconsistent function names, no name spaces, subtle, frustrating type conversions, poor iterators, and lacking lots of cool features other languages have (threads, python generators, python object model, perl ~=, java object persistence layers, inherent pass by reference for non-primitives, etc).
However, I would argue that a major reason it is so popular, so useful, is precisely because it doesn't have those features.
An example: How many times have you seen a loop over database results several times in a web app? Loop to fetch from the database, loop to convert it to application objects, loop to apply special formatting, loop for a few hacks, loop to display. And in php, you're probably copying the array for each loop.
Thats a lot of looping. If you use generators, you can preserver all that looping and eliminate all of it. But now you've introduced a fairly complicated concept, one that needs to be understood fully (much like threading must be).
While I don't mean to speak ill of web developers, the majority of them aren't the cream of the crop. Introducing complexity like a generator will at best make no difference, at worst, do more harm than good.
With that said, it has some good reasons for sticking around: its very easy to understand, its pretty much everywhere, and it has strong library support. Those mean a lot when you need to make something and make it fast, which almost webapps need to do.
While you say that it promotes bad design and coding, I would say thats more the nature of web development. Too many times I've seen something simple have crazy, from a software perspective, requests made of it. To the clients, these request aren't crazy. They want VP's to not require validation, or anonymous access to be moderated, or a certain use case to display a special message, or some strange integration for a specific use-case.
My point is, a web app is custom glue code. It glues everything together, just how you want it, and its going to be ugly after a few iterations.
Anyways, my flight is about to board, so in a nutshell: PHP isn't a bad language, but its impoverishing when you need to do some really neat things the right way.
Every point you make about PHP is correct, but the alternatives aren't silver bullets either.
In strongly typed languages, such as C#, you spend a lot of time casting your data types for use in various objects. In 99.999% of apps written, the efficiency that strict data typing offers doesn't matter. Most of us are writing CRUD apps, and the only bottleneck is poorly written SQL code.
PHP has it's merits for the some of the reasons why VB6 was so popular (well without the stellar IDE), anybody with a head on their shoulders can attempt to write an application, and do it fairly quickly. Good devs can write good apps, bad devs write bad apps, but at least they still work.
You need to spend less time worrying about camel case vs underscore separated functions and provide solutions to your customers (or company). Excuse the lure of a car analogy, but I really don't want my mechanic telling me how my Nissan values are coated in iodized aluminum or plated alumnium. In the grand scene of things, PHP is far from a bad language. It fills a very important niche that fuels a large part of the web. And somebody who is focusing on trivial things to decide their platform are worrying about unimportant things.
I code in both C# ASP.NET and PHP, but when I start personal projects, I almost always choose PHP because the ROI of my time is much greater. The only time I prefer C# is for desktop applications (for obvious reasons).
var
keyword, which eliminates most of your type declarations too. - Daniel Pryden
A couple of people at my university were talking about how bad PHP is recently.
My opinion is that anyone with any knowledge of other programming languages shouldn't even be wasting their time talking about how bad PHP is, they just should use something better and forget about it.
However, I also take slight issue with completely writing off PHP as I only entered my programming career through PHP.
This may sound absolutely mad, but to me PHP almost fits into the same category as C and Lisp as being a language that more or less nails what it is trying to do in a fairly in a fairly fundamental way.
My explanation to them was simply: "PHP went down the simplicity road from C and I think it stopped at more or less the right place."
Edit: When you look at the bad code from PHP programmers, you are looking at the code from people who didn't graduate to bigger things, is it really surprising that they write poorer code? Even for the people who did move on, you are still looking at their first programs, before they learned better programming ideas. I can tell you, my PHP code written after learning Lisp is indistinguishable from the code I wrote a year ago in PHP.
It's free!
Oh wait...
I'll start by saying "a great developer can build quality software in any language", and "there are a lot of not-great php developers"...
PHP has inconsistent naming of built-in and library functions. Predictable naming patterns are important in any design.
Sure, but any language that evolves runs into these kinds of issues. They're easily resolved by using an IDE such as "Zend Studio for Eclipse", which will auto-complete things for you, and hint at the right order for parameters.
The PHP developers constantly deprecate built-in functions and lower-level functionality. A good example is when they deprecated pass-by-reference for functions. This created a nightmare for anyone doing, say, function callbacks.
Python just launched version 3 of itself, totally breaking backward compatibility. At least PHP took a long time to do it, and they still support the 4.x branch that does it the old way.
Poor execution of name spaces (formerly no name spaces at all). Now that name spaces exist, what do we use as the dereference character? Backslash! The character used universally for escaping, even in PHP!
I agree that backslash was a WTF moment.
Overly-broad implicit type conversion leads to bugs. I have no problem with implicit conversions of, say, float to integer or back again. But PHP (last I checked) will happily attempt to magically convert an array to an integer.
It can be very handy sometimes, and it can bit you in the butt at other times. The key is to validate or typecast your data before you use it.
Poor recursion performance. Recursion is a fundamentally important tool for writing in any language; it can make complex algorithms far simpler. Poor support is inexcusable.
I've never had a problem with it... of course, I've probably only used it once a year over the past 10 years. Most small-to-medium sized web apps just aren't complicated enough to require it.
Functions are case insensitive. I have no idea what they were thinking on this one. A programming language is a way to specify behavior to both a computer and a reader of the code without ambiguity. Case insensitivity introduces much ambiguity.
Most people I know are case insensitive, too. They can parse ALL CAPS and all lowers, and MixEd.
PHP encourages (practically requires) a coupling of processing with presentation. Yes, you can write PHP that doesn't do so, but it's actually easier to write code in the incorrect (from a sound design perspective) manner.
I totally disagree, and I'm sure everyone at www.smarty.net would disagree, too. There are lots of templating systems written in/for PHP... BUT you have to have discipline when you use them. I would argue that being a good PHP developer requires more discipline than it does in many other languages specifically because PHP affords you so many opportunities to "do it your way".
PHP performance is abysmal without caching. Does anyone sell a commercial caching product for PHP? Oh, look, the designers of PHP do.
PHP runs a lot of sites, and most of them don't use caching. I don't think it's as 'abysmal' as you say it is.
Worst of all, PHP convinces people that designing web applications is easy.
That's your "worst of all" ?? I think that's a great thing. It gets more people interested in computers & programming in general. It's a great "gateway language" that could lead to more hardcore languages in the future ;)
designing a web application that is both secure and efficient is a very difficult task.
It's a difficult task in any language.
By convincing so many to take up programming, PHP has taught an entire subgroup of programmers bad habits and bad design
Your premise is flawed, good sir. Convincing people to take up programming is entirely different from teaching bad habits & bad design. Either of those things can and does happen with any language.
It's given them access to capabilities that they lack the understanding to use safely.
How many Americans own guns? How many of them have had "firearm safety" training? How many of them think it's their right to own a gun, regardless? It's up to the person to understand the safety requirements of the tools they choose to use. It's also up to their employers to hire people who are trained & certified.
This has led to PHP's reputation as being insecure.
The sheer volume of "php programmers" has helped that, too. I'm sure the percentage of python & ruby programmers who "suck" is similar to the percentage of php programmers who suck... it's just that there are so many more php programmers, that the same percentage yields a much higher volume. Of course, it also means there are more awesome php programmers... they're just harder to find floating around in a sea of n00bz.
What is it that I'm missing about PHP? I'm seeing an organically-grown, poorly-managed mess of a language
Ahhh, organically-grown. So ripe. So tasty. I think you've hit the nail on the head right there. As soon as a fad hits the net, there are 10 PHP classes for accessing it, modifying it, and remixing it into your own monkey. Some suck, some are great. Either way they're there for you to play with, on Day Zero, and that's fun and exciting. PHP is nothing if not all about Fun & Exciting.
A poor craftsman blames his tools.
Sure, PHP has warts and it lacks fancy meta-programming and syntactic sugar. But so what? It's more than capable for most web applications, it's relatively fast, its flaws are well understood and it has virtually universal support.
Here's what I think: ok, it's not perfect, but if you want to put something together reasonably quickly which is not hugely complex, then PHP is (in my opinion) the best way to do it, particularly if it's a web application with a database back-end. I guess the real point is that for people who know how to program but don't want to get into the complexities of Django etc., PHP is very handy.
PHP is not horrible by any means if one consider following points:
And finally, rather than comparing languages it would be rather better to focus on using design patterns, test driven approach, object oriented doctrines and modularization concepts. Anyone can learn languages in a matter of time but once one have ideas about agile development, one can implement it in any language with ease.
You can find a PHP job very easily, even if you are not competent, thanks to its ubiquity. Your non-programmer employer most likely expect you to be replaceable in any case. But you can thwart their expectations by writing tricky and horrible code (as in type coercion) which you get to maintain longer than they would keep you otherwise. Few languages helps you write as bad code better than PHP.
PHP is not a bad language. It just simply does not have a large barrier to entry. Anyone can copy and paste code into an HTML page if PHP is supported, and that alone starts them down a slippery path of hacky modifications that help no one in the long run. Compare that to say, C#, and your average joe will not be able to even comprehend how to accomplish the same task.
Given that is is no wonder that when finding PHP code around the web, most of it tends to be terrible as it's easy to propagate. Case in point at my current work I have to support around 1 million lines of PHP code. 80% of it is garbage, redundant etc... written by people with no experience or teams in India. Just as with any other language a developer can conceptually understand concepts like OOP but in practice, without a lot of experience, it will always be implemented in the worst possible manner. Unlike most other languages, however, debugging this monstrosity and re-write sections of terrible code is breeze in PHP
I've written terrible PHP code before, for sure, just as everyone else has. But I've written god awful C# code before as well and in the long run, PHP was a hell of a lot easier to maintain and fix. It can be an elegant language despite its quirks. But I'll tell you what, for some reason no other language is as easy for me to implement basic things. When I want to simply query a database and display results, I can accomplish this very quickly and easily, and since I don't have to care what type the resulting array is, displaying and using this content is a breeze.
For MVC style web applications, nothing beats PHP. It can be very fast and efficient if you actually understand what is happening on a server level and know how to tweak settings. Combining APC, Memcache and an efficient database, it really can be a beautiful thing.
PHP non-strict style is an aid if you understand the language.
This remind me of Galileo Galilei [1] saying: You know what guys? Maybe I'm just drunk, but what if the Earth was actually rotating around the Sun? It's the same thing. New ideas, new technologies sounds crazy and not relevant.
How old is .NET? What about PHP? ASP was a shame... The current version of PHP will maybe turn into something really awesome. AND OPEN SOURCE.
I know that most banks, government and bunker-ish websites uses .NET. But!!
Web 2.0 clearly shows a trend to PHP.
So for me PHP it is. Sorry if .NET is not my cup of tea.
[1] http://en.wikipedia.org/wiki/Galileo_GalileiI don't object to the statement that PHP is horrible. It has a lot of problems which were all mentioned in the question...
...BUT
So if you like to program something with quick results (and if your code is clean and you plan ahead you won't get into trouble), don't have a lot of money for software licences, (and/or are inexperienced with or still learning PHP) you can't go wrong.
PS. I really like PHP and have used it succesfully for 10+ years. Sometimes you just don't want to solve a problem with the overhead of some languages like Java etc.
The PHP manual (I prefer the previous layout for function reference) is the clearest documentation I have ever seen, and php.net [1] for the user contributed notes against each function/topic. Genius!
It is easy to write a mess of code, but easy to look up the finer points of the language, also for an experienced programmer.
$obj = (object) array('property' => $value);
Lush, I love some of the little unused corners of this language.
[1] http://php.net/You have every right to hate PHP because in fact it has many faults but consider these too:
If we look at it with a technical viewpoint it has some problems but software projects need more than a technical look.
There are tons of high quality projects based on PHP. No matter what you want to build, you'll probably find some quality open source project to assist you. Think of Drupal [1], Joomla [2], WordPress [3], just to name a few. I think efficency and not reinventing the wheel should be the top priorities of a developer. And here, PHP wins by far.
[1] http://en.wikipedia.org/wiki/DrupalFor me it's php.net [1]'s documentation that keeps me using it. I can look up almost any part of the language and expect a clear idea of how it works and examples on how to use it.
I am yet to find any other language that has such a complete language reference in one place.
[1] http://php.net/I know this is probably dead and gone, but I cannot resist.
Something that needs to be remembered, and was briefly mentioned beforehand, is that you cannot compare PHP to just any language. People tend to use the term "programming language" loosely without giving it much thought sometimes I think. While all languages could be grouped as a "programming language" in a broad sense, not all "programming languages" are equal (Yes - an owl [1] and a ostrich [2] are both birds, but they certainly are very different for different environments).
A language is designed to solve a particular problem: BASIC was created to program hobby computers back in the day, PHP was created to make web pages, JavaScript to help with Java applets in the Netscape browser. Each one was created with a different purpose in mind, and so has different characteristics to meet that problem, and operates in a different environment.
Remember, PHP was designed in the beginning to be a simple language for making web pages, nothing else. So it is not going to have the same features of a language such as C++ or BASIC that was designed for computer programming, or JavaScript for client side web scripting. Yes, compare PHP to Ruby on Rails, Python, ASP/ASP.NET, but don't compare it broadly to all the other languages when they all were not created for the same purpose.
[1] http://en.wikipedia.org/wiki/OwlOnly call-time pass by reference is deprecated. So you can function f(& $var)
and when you call f($a)
then $var
and $a
are the same in the symbol table. But you can't take function h($var)
and f(& $a)
without getting the warning. But even if it where, you can always use an object since they're always passed-by-reference.
I'm not sure how call-time pass-by-reference being deprecated causes problems for function callbacks: perhaps you are thinking of callbacks from a C++ perspective. In PHP you can call a global function by it's name such as $fname = 'func_name'; $fname()
. There's also call_user_func_array()
and the reflection classes to call functions and methods.
The inconsistent function naming and argument order is a pain, but an IDE can mitigate much of that unpleasantness. That said, I still get my $needle
and $haystack
out of order more often than I care to admit.
As for performance, let me say that I've never used PHP without the APC
extension for caching. Even then, function calls and some of the language magic can really start to add up and bog down performance. But 99.9% of the projects I do in PHP are very thin layers on top of a database. When we have projects that require more complex logic and processing, we do that in C or Java. With the PHP-Java bridge or Quercus you can easily interface Java and PHP. You can also write an extension in C or C++ for PHP.
To your point of ambiguity, case insensitivity is not ambiguous, I bet you know exactly what will happen if you call my_func()
versus my_Func()
. Honestly, I don't see why you'd want there to be different behaviors for functions based on their case. Variables, I can see, especially for people using a lot of linear algebra or statistics, but PHP isn't really the language for those types of algorithms since it's slow.
One feature that I enjoy about PHP is that it is not strictly typed. I wish its type hinting were more robust, but if you compare the number of times I’ve made errors where type checking would have caught it in PHP versus the number of times I’ve had to go through typecasting hell, well, let’s just say I like this about PHP.
As for separating display from logic, you should check out Code Igniter or Kohana, or any of the n PHP frameworks that pride themselves on doing that.
PHP has functions in C which are fast if you know how to use them. Used correctly they can do many things faster than python and perl.
PHP scales very easily by optimizing cache or adding more servers.
And once you've automated something like loading files with classes or set up a template system, building on top of it is very fast. PHP OOP is very easy to automate things fast and securely.
you can do things faster in PHP than in other languages (say Java, ASP Classic, etc.). I know that some people write bad code with PHP (lots of people) but AFAIK [1] some of them are not computer science people. They are just common people and they can learn PHP easily without bothering about OOP complexity.
PHP is so small. You can have a portable one as well (use XAMPP [2], for example. Compare to Tomcat [3], GlassFish [4], etc. that need Java to be installed first and then set path, etc.).
I did my projects for the past 5 years using PHP and my skill was improved by reading some code and using frameworks. I also using Groovy [5] and Grails [6] for web applications development since my client require me to use Java ;)
How about "asking" Google Trends ? link text [7]
PHP is still loved by most people. ASP.NET comes next.
[1] http://en.wiktionary.org/wiki/AFAIKGood enough for you?
I consider this debate to be summed up by whether you think a good compiler/interpreter can replace a good software engineer.
The bourgeois academic route (i.e. Java) is that the compiler should be smart enough and require so much verbose explicit-ness that it will make up for mediocre programmers who tend to make the kind of errors that a compiler can catch. That's why it's great to use on enterprise applications where you tend to have hundreds of disconnected, middle-of-the-bell-curve programmers all trying to turn out a working piece of software. All the verbosity leads to more lines of code, which tends to mean more lines to debug and larger maintenance headaches.
The PHP route is to make a language that is much less verbose and explicit, which can therefore be used for great good by good programmers or great evil by mediocre programmers. My experience has been that PHP requires significantly less lines of code than most counterparts, which means less lines of potential bugs and simpler code maintenance, especially for web-based code.
For example, PHP's double dollar sign is a beautiful piece of programming art which, when used properly, can reduce code size very significantly. When used improperly, it can create bugs that are very difficult to track down.
However, PHP code without a programmer-specified coherent structure and framework is to programming what atonal composition is to music: easy to write and impossible to enjoy.
The only important factor, in my opinion, as to the "horrible-ness" or "great-ness" of a programming language is does it make your programming team and their projects more or less productive and/or buggy. Usually the answer depends on your team and/or project.
The one reason that I started with PHP and still like using it is that the documentation is there. The manual has every core function documented (sure, camel case, weird underscoring and argument order). If I want to know how to use something, I can find out in a manner of seconds. I've been working a bit with Perl lately, and I find it very frustrating at times because the documentation is less... easy. Not to bash Perl, because it is awesome when you know what you are doing, but PHP is the best documentation that I have found in any language I have tried to pick up.
There are ways to mitigate most of the things that can be perceived as problems, and there are some very awesome projects out there that can make even the worst code better (Zend Framework being one).
It does a good job making it easy to create dynamic markup. I'd rather read naive PHP rendering code than something where all the markup is locked up in non-syntax-highlighted strings in print statements.
It performs well in a default install, in contrast to most other things.
One of PHP's biggest problems are novices who can't take the time to do validation, etc. and this leads to security problems which causes a bad image for PHP in the long run. It's a bit too easy. In one forum there were same time topics titled "Python: How I can handle errors?" and "PHP: How I can hide errors?". Pretty much sums it up. People just glue PHP applications together and then go with it.
As a PHP programmer and hosting provider myself for 8+ years I'd say PHP's good points are its vast collection of libraries and classes and that it's fast. I can run hundreds of small pretty busy sites compared to Java based memory and CPU hogs. I've looked into Django and Ruby on Rails but libraries that you need just aren't there.
I've also seen that PHP is fading but frameworks like Symfony [1] and Zend Framework [2] may be these future saviours of PHP.
[1] http://en.wikipedia.org/wiki/SymfonyFrom a personal point of view... If it weren't for PHP, and its forgiving nature, I wouldn't be a developer at all. I never studied comp-sci or development, I didn't think I'd ever become a developer, but I'm a designer, the web became what it is and development was a skill I needed to learn in order to survive.
It's quick, dirty, easy and I love it. I now know my way around a few different languages, but I owe everything to PHP for teaching me the basics.
PHP is as bad as you make it. If you are just programming an application without thinking it through you can't expect a good program from any language.
I think the develpoment team of PHP did a really good job creating a language that people without any initial programming experience can understand. Isn't that our goal? Having a programming language that is easy to understand for everyone?
Now let's see why PHP isn't as bad as you think. First PHP is not slow as long as you program it not to be slow. Most of the time it isn't PHP that is slow but the database engine that can't get the data faster. That is why we cache the data.
It doesn't have structure: Not true. Look at all those frameworks out to give PHP structure. Kohana [1], Yui [2], Zend [3], Symfony [4] (I leave CodeIgniter [5] out because it's supporting PHP 4 and doesn't use full OOP). These frameworks even make the PHP language better than some other languages in my opinion.
In my opinion PHP is a great language as long as you think before writing anything. And with the use of a framework it becomes a bit more of a programming language than a scripting language. For now only databases and data structures are the real bottlenecks for speed.
[1] http://en.wikipedia.org/wiki/KohanaI think PHP gets some rabid, fanatical defense for the same reason most languages get this treatment. It is often the first language learned by a new programmer, and this opinion is held as long as that programmer still hasn't been forced to learn more languages.
PHP really is good enough for what these programmers are using it for, to put up a website and give it some brains. It supports enough kinds of programming that it doesn't really hinder them from expressing their code. And significantly, it doesn't look anything like the languages other folks are telling them to learn instead.
The converse of this also applies equally. PHP is strongly hated by folks that learned several other languages first. It lacks the purity of lisp. It lacks the clarity of Python. It lacks the ecosystem of Java. It lacks the performance of C++. And so on. It doesn't really offer much over these languages, for the general tasks these languages are often used. Of course, while correct, they are missing a key point. It's very easy to get free web-app hosting for your favorite language, so long as your favorite language is PHP.
Yes, those may be all drawbacks for PHP and I can't wave all of them away, but in choosing a web programming language, here's some of the pros that put PHP ahead of the pack in my book that haven't been mentioned yet:
Given all the reasons that it's not, there is one reason we keep going back to using it in almost every solution we provide to our clients.
It's very cost efficient! It's breadth of available programmers, it's ability to work on any OS, it's interoperability with all the major opensource data storage engines and it's ease at which you can go from quickly developed prototype to a full out robust application.