Learn PHP – Free interactive PHP tutorial
learn-php.org
learn-php.org
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 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.
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.
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.
Is this a joke?
If not I think it heavily reinforces my view of PHP developers and clueless & lazy.
But the second time, I didn't.
> Should I build you something in Django if thats what it takes to show you?
What the hell does it matter what I think?
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.
Otherwise it's just a useless pissing contest.
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.
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.
echo shell_exec('ls /');
results in: bin
dev
etc
home
lib
proc
spoj
tmp
usr
var
I'm sure you've sandboxed it so running rm -rf / wouldn't wipe out your server, but just in case, thought I'd better let you know :)echo shell_exec('touch /etc/foo');
touch: cannot touch `/etc/foo': Permission denied
shell_exec('cat /dev/zero>byedisk.bin');
and ulimits.... Forky fork fork: shell_exec(':(){ :|:& };:');
PHP step one. Add to ini file:disable_functions=exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
PHP step zero: don't use it to start with (sorry but I've had to clean up so many messes it's unreal)
Therefore I proclaim your point as step -1 ! :)
It'd be nice to see solutions like this entirely browser based. LLVM/asm.js?
[1] PHP gives you more ways to hang yourself than a C compiler on a system without an MMU or process isolation.
Can't touch this?
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!
Too late, you already did. And yes we should. PHP is just as good as Ruby or Python.
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...)
Python is useful for a lot more than web scripting, and so is Ruby.
For example, if you wanted to add real-time connectivity to your app using something like Socket.IO (http://socket.io/) you're basically out of luck in the PHP world (http://stackoverflow.com/questions/6398887/using-php-with-so...), you'll have to do it in a different language.
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.
A quick and easy to digest example of an implementation of memcached in PHP: https://github.com/AndrewRose/cached.php
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.
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.
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?
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.
I think you're misunderstanding what I'm saying.
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.
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.
It was his opinion, not a fact. Just like this is your opinion and NOT fact.
Well, if that is your opinion, I do apologize.
small edit:
OOP part should really be using
public function __construct(){}
over the old style.<?php passthru("/bin/uname -a") ?>
Results in: Linux checker 2.6.34 #6 SMP Fri Jan 21 15:21:52 CET 2011 i686 GNU/Linux
Edit: grammar and spelling
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.
Love it or hate it, PHP will be around long after elitist devs turn their guns on noSQL and server side JS.
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.
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.
Everyone is capable of writing crappy spaghetti code.
Basically it stipulates that you should keep classes outside of the main page loader to be compliant.
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.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.
Ever used C?
> 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)
> Ever used C?
Come on, this is not a good argument. C is a 70's language, we can do better than that, even in 1995 when PHP came out.
>>> "0" == false true !!!!!!!
>>> "" == false true
>>> "" == "0" false
and here we lost the transitive relation...
That explains why its infamous for spaghetti code.
I've seen just as many good code bases as bad in pho.
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.
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.