PHP is probably the language with the best return on investment (of time spent learning) currently. It is extremely easy, and is fast to prototype stuff because of the high level nature. While the language is not as expressive as other languages such as Ruby or Python, it is easy to move on later, but PHP provides everything to get things done and deploy easily your simple application in minimal time.
A lot of good programmers today started their web experiences with PHP. Now probably they are using the latest cool thing, but it served as the "BASIC" of our times, and is still active and trying to fix its issues.
Also, and this is not a PHP merit, but a disaster with other dynamic languages such as Ruby, the performance you get by default with a simple PHP application, is good enough that is almost always the DB to blame, not the front-end, when there are issues under load.
I have been a PHP programmer since long and while I do wish to go up for Django or RoR but I usually get put off by the amount of time I need to spend getting around both. On the other hand, it is so easy to get started with any PHP framework (except Zend, of course) and thats what I love, easiness to get encouraging productive output but seeing the people's prejudice, I feel that I would have to more or less go up for them.
I hate the fact how difficult is to associate yourself as "good PHP developer" amongst clueless 3$/hr script kiddies but if you are able to call yourself as a Django developer, you are automatically in the category of a good programmer.
Learn Python and/or Ruby. Not for the salary bracket it will put you into, but for the horizons it will broaden in terms of how you understand programming.
Don't learn Django or RoR either. You'll just be solving the same problem in a different way. Intead, try something entirely new--write a chat or job server with Twisted, try your hand at image processing, write some ML classifiers, and so forth. It's not as hard or out of reach as you'd think. Imagine a fun problem to solve--something you've always wanted your computer to do (perhaps something that irks you, that you want to automate) and just do it!
You'll find yourself in that "other category" without that having been your objective at all, and you'll have much more to show for it.
The problem with a low barrier to entry is that there is less filtering, so you get very bad programmers claiming to be experienced developers. However a good programmer can surely use PHP constructs (that are not so much different than the ones offered by other languages at the same level of abstraction) to provide modular and easy to manage code. If the customer wants the cheap developer, she or he will later learn that there is a real difference, and next time will be willing to pay more, as it is actually a way to pay less in the long run...
I spent some time learning Python and Django to some degree. Python is easy and I wish I could write more in it. Django felt less awesome, but still pretty good, except when it came to deploying it on my web hosting (Dreamhost). At the time, they only sort of supported it.
But I always fall back on PHP. I know it - it works, warts and all. It's maybe not a great scripting language, but it's a good one and it has the advantage of being almost ubiquitous.
Why clueless and lazy? We know the strengths and weaknesses of PHP and other programming languages. Thing is, while we really do appreciate what others offer it's still easier / cheaper / better (choose whichever sounds good to you) to "import" good ideas from <insert language> than to change whole stack.
Clueless and lazy because the amount of time to "get your head around" django and python is so absurdly minimal for anyone who has done any web development at all. It is incredibly straightforward, and finding that "too much" pretty much disqualifies someone from being a competent developer.
I don't wish to take it personally but these kind of remarks make me furious. Should I build you something in Django if thats what it takes to show you? because I am sure I will. By getting my head around, I didn't necessarily meant I was too foolish to understand anything but I had my problems. There wasnt any default schema for urls, each route needed a new one, managing database and creating tables required a console based code generator, setting up django with apache required an effort, the abstraction of app vs website was quite peculiar, and some other issues I don't recall. Call it my ignorance, stupidity, daftness that I failed at so basic stuff but thats my side of the story.
App vs website is bizarre the first time you encounter it - in my mind it would have been better them calling "projects" "deployments". The first time I worked with django I developed my application/project inside-out.
But the second time, I didn't.
> Should I build you something in Django if thats what it takes to show you?
Also, despite all the naysayers PHP's going through a bit of a revival at the moment. It's certainly not dying.
It's recently got Composer as an awesome package manager, the Laravel 4 framework, new features like short array syntax, closures etc and support from more PaaS (e.g. Google App engine). The community is really getting behind all this as well, which will help bring up the reputation.
I'd still recommend anyone to learn PHP as their first programming language. It's still the easiest to hack your first idea together, there's more jobs than any other language and the standard of code is improving now the language has the features and infrastructure it needs.
If someone wants to learn webdev, I would recommend javascript as a first language. Just use something like parse/firebase and you don't need sever-side at all.
PHP isn't going through any sort of "revival" stage or surge in growth.
Composer is a cheap clone of NPM with horrible performance (don't believe me? wait until you're in production with 20+ composer dependencies). Closures have been around for over 3 years now. Laravel brings nothing new to the table that wasn't already there before it's existence (and dear god I hope no more of the pretentious Ruby "artisan programmer" attitude continues to bleed over).
The reason PHP is not dying is because in SPITE of having a sub-par language syntax, inherently flawed security design, and the newer "me-too" bolted-on features you mention, it still continues to be dead simple to install, learn, and get a working proof of concept up and running.
Good ideas become proof of concepts become a sold product quickly with PHP.
The problem with that attitude is that real-world usage is what matters if you're benchmarking or evaluating for your own use.
The vast majority of people who use Ruby for web development are using Rails (because Rails is a large part of what makes Ruby effective and attractive for web development - in general, YMMV), so you can't make realistic performance comparisons without comparing commonly-used stacks.
Isn't it more like public-facing app step one: Don't run user-supplied code? This in particular hardly seems to be a php issue. Sandboxing isn't trivial in most languages/environments.
Regardless if its a good thing or not the fact remains since it is popular today it will be used for years to come. Someone will have to know how that one PHP app works that your company made 5 years ago and refuses to update.
Not trying to bash on PHP or perpetuate the knee-jerk PHP hate, but should we really encourage people to learn PHP?
Imagine the effects if the mainstream web development focus would shift from PHP to some more thought-through language(+framework?). The PHP-development community produces some really great things, imagine all that effort expressed through better and more efficient tools!
I don't know if you're deliberately making a disgusting lie, a blatant troll or just lack knowledge. Either way, I wish to state, as someone who has several years of actual professional experience of all three, in very strong terms that this comment is nowhere near the truth.
But about the parent's question: I believe that no learning is ever wasted, so go ahead and learn PHP, but it might be a good idea to realize that it's quite unique in how badly designed it is, and that the rest of the programming world does many things differently.
Maybe, but the standard library always makes my heart beat faster. We're talking about the language where you have pearls like strcspn, strtr, strstr, strpbrk and at least three different naming styles for the same group of functions (e.g. for strings strtr, str_replace, trim).
And good luck with handling non ascii data with the standard library.
PHP would need a highly deprecating major version to clean all the rubbish, but it will never happen (see the history of PHP 6.0)
disclaimer: I'm a PHP developer (during the day, but at night...)
I don't use PHP much - but if you're making a website, why is being able to do things other than make websites important? I wouldn't use Ruby or Python to make desktop or mobile apps anyway.
I think people who invest a lot of time in learning PHP are getting less bang for their buck than they would learning Ruby or Python where their knowledge can be applied to broader disciplines.
Do you need to process audio files? Maybe write a quick script to scaffold some Objective-C or Java code for your mobile app? What about writing a persistent process that watches for files on your network, processes them and uploads them to Dropbox?
All these things are really easy with Ruby, Python, or even NodeJS, you just glue together a few off the shelf modules and you're basically done. PHP is way out of its element in these sorts of situations.
Yeah, like I'm going to use that in a production environment.
The libevent bindings are pretty wobbly in most languages other than C, with the exception of things like NodeJS. Plus, that project is pretty much abandoned.
It's an example of what can be done. And yes libevent has been abandoned but has also been superseded by http://us3.php.net/event
Your attitude is very insulting, did you know that? You have an obvious lack of understanding of the PHP ecosystem yet feel you can belittle it with off the cuff comments at will. Please stop this behavior as it drags the entire developer community down.
I've been spending a lot of time in the "PHP ecosystem" and honestly it's a disaster. It's comparable to a country like Brazil.
In some areas people are very well off, they have developer tools, they have best practices, they produce useful, workable code. Yet they're the elite minority.
Most people have nothing, get by with scraps of code scavenged from message boards or obsolete technical books, and bang together applications that are the code equivalent of a barrio. The level of ignorance about even the most rudimentary things like SQL escaping or string concatenation vs. interpolation is staggering.
Let me be honest, I don't care if I'm insulting. I'm not saying these things to make friends or win karma. I'm saying them because PHP has problems and I don't see a lot of effort being made to reach out to the average developer learning PHP who's stumbling along, all wrong if only because they don't know better and nobody's telling them otherwise.
I'm not going to suggest that other communities don't have problems, Ruby has a standard library that's embarrassingly bad, Python has a version schism they're at a loss to resolve, NodeJS is being held back by the crippling limitations of the V8 engine, but PHP is all that and more.
For example, if you're working on a complicated C++ application and need a simple script to emit some templated files you could roll this in Python, Ruby or even Perl and a seasoned developer would be okay with that. If you wrote it in PHP, though, they'd have reservations. Why, of all the scripting languages out there, would you pick that one? Why is PHP such an albatross?
I spent a lot of time in the Perl community back when it was still a thing and witnessed what happened to a language when people didn't complain or, as you say, insult it enough. Unconditional love isn't a bad thing when dealing with people, I'm all for things being civilized, but it's toxic when applied to programming languages.
You love your pet language too much and you'll smother it, every time. Smalltalk suffered greatly because of this attitude, people pretty much loved it to death.
You want your favorite language to evolve? Be its worst enemy. Find things about it you hate so much you can't stand to endure them any more and fix them. Bitch about things that aren't right, take a stand, and be the squeaky wheel.
Every time I get into one of these discussions about PHP with someone who seems to be a big supporter of the language, I ask for one thing: Don't just tell me PHP is great, show me. Is there a guide to PHP better than PHP the Right Way (http://phptherightway.com/) that encourages people to do things correctly so they can have an experience like yours?
Nice rant. But it doesn't change the very simple fact that you have been spreading ignorance in regard to PHPs capabilities. You also show nothing but a very subjective view of PHP based on, what I can only guess at, is your own gut feelings.
On the contrary, I've been doing what is as much as "Doctors Without Borders", trying to get new developers on Stack Overflow using PHP to stop doing things that are damaging. There is a non-stop influx of those that have almost no idea what they're doing, and no idea where to turn for help, composing these desperate pleas to explain what's often something so elementary nobody bothers to discuss it.
I don't know how many hours I've spent answering simple questions and promoting incrementally better practices, but it's got to be in the hundreds by now. I'm not even a PHP developer, I'm only focusing on the intersection between PHP and MySQL where a lot of deadly dangerous mistakes can be made, and there's not much in the way of push-back when you're going horribly awry.
Perhaps this gives me the perspective of someone working in the emergency room, where everyone seems to be on the brink of death, which is not at all like the real world. I can only report on what I'm experiencing.
If there were better resources I could link to as a sort of intervention, to help mitigate how bad this can be, I'd like to know. Right now it's like a never-ending stream of new coders with some serious MySQL escaping issues that they don't know about and problems related to the completely awful training material they've been exposed to.
If you think I'm exaggerating, just look at the sorts of questions that show up constantly and demonstrate how real-world PHP developers are producing code. Examples are so rife you can barely find a question without serious problems: http://stackoverflow.com/questions/20252023/how-to-create-au... is all too typical. Why are people writing code this way?
This does not happen in the Python or Ruby worlds. You'll get ambushed by people who will coach you in how to use Django or Rails.
"It's stuck as web development language due to design constraints"
PHP comes with a CLI SAPI that allows you to use it on the command line just like python, ruby etc and has done so since version 4.2.0 (released April 2002). I've written and maintained many cli tools and deamons in PHP over the last 11 years with great success so please get your facts straight before perpetuating falsehoods .. sorry, but I'm getting pretty sick of the ill-informed PHP bashing going on round these parts.
It's free to criticize PHP; that's why everybody does it, but at the end of the day the quality of a certain product depends on the programmer, not the language.
I would say from a usability / opportunity of employment standpoint they are equal, but PHP seems when working with it far less "designed" than Python and Ruby in my opinion. Things like the inconsistency of single word / snake case / camelcase in method names etc.
What about people working with legacy code? When I started at my current employer there was a quite a chunk of code written in PHP so learning some PHP wasn't optional.
I like it! I frequent the PHP channel on Freenode often, and one thing that would probably be wise is linking http://www.phptherightway.com/ somewhere in there to try and influence coders to not make bad decisions off the bat.
There are plenty of tutorials around the net which teach the basics quite nicely but none in my eye rank high because none teach how to avoid what PHP is infamous for : spaghetti code. Unknowingly, newbies get the idea of making website as slapping together PHP, HTML in one page. I feel there is one critical section which every author misses, Basics of MVC and getting started with a framework.
> how to avoid what PHP has been infamous for : spaghetti code
Spaghetti code is not what PHP is infamous for. Spaghetti code can be written in any language. PHP is infamous for all library functions being in the global scope, lack of sane naming conventions for those things, terrible type conversions, unsafe libraries, starting php with every request, being able to drop raw php right into html templates - what it was initially designed for, and being just a general web programming language not much useful in any other context. It's also got a bad wrap for being the language of choice for people who do not wish to learn any other language or anything about computer science or computers.
PHP is what happened when people learned HTML and saw that once they got to forms they needed something else.
> lack of sane naming conventions for those things
Absolutely annoying but also fairly minimal. Mostly an issue in the string & array functions.
> terrible type conversions
Weak typing has to coerce somehow. Javascript is equally "terrible" at times.
> unsafe libraries
Such as? All the major libraries are thread-safe that I'm aware of
> starting php with every request
PHP exists outside of the web, and even in the web environment, you can run it as fastcgi since inception as a persistent daemon and php-fpm is the standard daemon now as well.
> being able to drop raw php right into html templates
I view that as a feature (which is often abused by beginners)
I think frameworks such as Laravel and Symphony go a long way towards addressing a lot of these concerns. Although things such as global functions and naming persist, PHP offers easy deployment for new developers and is available on almost all low-cost web hosts that is a major benefit and a must-have for less experienced developers.
Depending on your project, if most of your code lives in the front-end, using Laravel/PHP for an API back-end is a nice option these days. It all depends on what you are trying to accomplish and your available knowledge and resources.
One cause of the spaghetti code was the mixing of business logic and of presentation. The separation of concern was easier in smarter languages (like ruby or scala) than in php. Nowadays, templating and presentation is mostly performed on the client side and the server handles only the business. As a result, there is less difference between ruby and php. Nevertheless, the event style of javascript (scala ?) provides better performances.
Why should PHP "force" anything? That's one of PHP's strengths: the ability to be everything from a simple dynamic webpage to a full blown app. That's like saying "I wish someone would make a hammer that only strikes nails, because I'm a poor craftsman and keep hitting my thumb."
Love it or hate it, PHP will be around long after elitist devs turn their guns on noSQL and server side JS.
I agree. At it's PHP is just a template language. There are many great PHP MVC framworks that have evolved over the years to incorporate many "best practices". The choice should be up to the developer depending on the project.
I'm assuming you meant "At its core, PHP is just a template language." That's a ridiculous, extremely over-generalized assertion.
I don't know of many "template languages" that treat classes as first-class citizens, has an in-depth, thorough unit testing framework, traits, closures, and and and.
I'm sure you get my idea? PHP may have been much simpler at its inception - it is not the same beast now.
ITT: People who haven't used PHP since 4.2 think they know what the language is like and base all their opinions on a language version over 10 years old.
I hate when PHP pops up here on HN, 90% of the people flapping their gabs don't or haven't used PHP for many many years, and when they did it was some Indian's crap code so they spend their time talking shit about a language because they had to fix a bug in Hinderbar's PHP spaghetti from 2003.
Actually the ability to mix PHP and "HTML" is the only reason I still use PHP occasionally. Sometimes, I have a plain-text file, and would like to use variables or simple loops in it. The best way to do this is PHP!
For example, say I want to plot a couple of data columns with gnuplot (an open source plotting program) into several images. I can write a PHP script "myplot.plt.php" that generates a gnuplot script (untested):
set terminal png enhanced
<?php
for ($i = 2; $i <= 4; $i++) {
$outputfile = "plot$i.png"
echo <<EOT
set output "$outputfile"
plot "data.txt" u 1:$i
EOT;
}
?>
and then invoke it from gnuplot with
load "< php myplot.plt.php"
This is a stupid example, but it gets really powerful when you dynamically calculate labels, element positions, etc.. PHP may be a crappy language for web development, but it is a really nice macro language, and has really powerful string processing features, making it ideal for this kind of hack.
While not enforced at the language level, PSR-1 states that "Files SHOULD either declare symbols (classes, functions, constants, etc.) or cause side-effects (e.g. generate output, change .ini settings, etc.) but SHOULD NOT do both."
Basically it stipulates that you should keep classes outside of the main page loader to be compliant.
> It's also got a bad wrap for being the language of choice for people who do not wish to learn any other language or anything about computer science or computers.
That explains why its infamous for spaghetti code.
Part of it is that PHP has evolved to address some very web-specific needs; in this process, developers of all skill levels have tacked on functionality which tends to give it more of a "thrown together" look which may be horrifying to developers who prefer languages that have been more carefully cultivated.
Part of it is a tribal, "Coke vs. Pepsi" kind of thing: the thing I am familiar with is good, what I am not familiar with is threatening and/or bad.
Part of it is because there are some downright terrible examples of PHP code out there. One of PHP's implementation strengths is a PR weakness: it is very easy for complete beginners to use it. It's like a zero-entry pool: anybody who wants to get into the pool can get into the pool. Some of those people shouldn't go into the deep end, but do so anyway.... and the byproduct of this can be horrifying and perhaps counterproductive for others.
As a PHP developer for 5+ years (with plenty of experience prior with ASP.NET and ColdFusion), I can attest that the language is a bit homely and doesn't posess a lot of cool features supported by other languages. But it works, it works well at what it was designed for, and continues to evolve (albeit slowly sometimes).
It's an adjustable wrench set that sometimes gets criticized because it doesn't include screwdrivers or hammers.
I might want to add that since PHP is so available (it really is) - it's easy to throw functionality together get it "working" and try selling it - the buyers of course getting disappointed and thus hating PHP.
And that hiring a PHP developer with "experience" doesn't really mean much, so a hiring person/firm that is not entirely specific with requirements will get really angry and disappointed with the results.
This can be avoided quite easily by not being a cheap SOB (There's no such thing as 800$/month Sr dedicated developer), choosing a developer with proper references and actually planning the project before starting to work on it.
1) PHP allows you to go wild and embed PHP inside HTML code. This causes your code to be unreadable and unstructured when it grows. Other languages just can't do it, so you're forced to use MVC, which is nicer by design.
2) As a language, it is not that advanced. It has a single namespace, and most of the functions used commonly in PHP are not object oriented. It also does not have advanced structures such as iterators, coroutines, etc.
3) There's $ signs everywhere.
1) the key word in this is ALLOWS.
My car ALLOWS me to drive it off a fucking bridge, but does that mean it’s the fault of the car if I choose to do that?
2) define advanced. I’ve seen Java web apps that needed stupidly complex getters and setters just to be able to handle a form post with a variable number of fields. How much of what PHP does out of the box, does a language like ruby or python support, and how much requires a framework like Rails or Django?
3) You are a fucking idiot. That sentence has just as much weight as your third point, possibly more so.
A lot of good programmers today started their web experiences with PHP. Now probably they are using the latest cool thing, but it served as the "BASIC" of our times, and is still active and trying to fix its issues.
Also, and this is not a PHP merit, but a disaster with other dynamic languages such as Ruby, the performance you get by default with a simple PHP application, is good enough that is almost always the DB to blame, not the front-end, when there are issues under load.