14 ms·
I Like PHP
- brendoncrawford 15y ago>Either you like both or you don’t like either, there is no claim you can make about PHP that can’t be made about C as well Except that PHP is terrible for systems programming?
- j_col 15y agoAnd PHP has super-aggressive garbage collection and C has none. And C compiles to machine code and PHP compiles to optcode. And...wait a second, why are we comparing this two unrelated technologies again?
- dillon 15y agoYou say if you make one assumption about C, you have to say the same about PHP. Well, PHP is academic, C is not. C is fast, PHP is not. I would only have agreed with your post if it were PHP and C++. C++ is academic and it's not slow but it is slower. You also say that you either like both PHP and C, or you like neither. Well what about Lua, Python... or any other embed-able language? Most Python programmers would say they don't like PHP but love C, because the languages work well together, same with PERL as well. You could say that you either like both C++ and PHP or you like none. Maybe, because PHP can compile to C++ to become extremely fast, which is why Facebook and Yahoo both use PHP because it can be fast and it is well documented. It should not be compared to C though. (Note: I contradict myself, PHP by itself is slow. PHP is not fast whatsoever. C++ is a low level language which is the only reason why it's fast and I think it's awesome that PHP can compile to C++. I'm in no way against PHP and I'm not encouraging people to stray away from the language. I was just pointing a simple error in this post.)
- aninteger 15y agoYes of course it's slow. It's interpreted and for 80% of sites out there that's fine. For the other 20% you compile the php down to C/C++
- BDFL_Xenu 15y agoPHP is academic?! What definition of academic could you possibly be using?! The blasted thing doesn't even respect basic things like transitivity in its most commonly used equality operator, its author says that he hated programming and didn't know how to write a parser when he first implemented it. And the thing as far as I know doesn't have a specified grammar. It just disregards as much of the body of knowledge of computing as it can while still actually running on a computer. If anything, C has a much more academic pedigree, being born in an industrial research lab and having /gasp/ an specification.
- masklinn 15y ago> PHP is academic Uh... could you explain how you arrived to this assertion? Because as far as I can see, PHP definitely is not academic. The bloody thing started as a hodge-podge collection of Perl scripts, and to this day it still does not have anything even remotely close to a formal grammar. A language in which `foo()[1];` is a syntax error even though `$a = foo(); $a[1];` is valid code most definitely is not academic.
- jrockway 15y agoActually, it's parsed with a rather simple yacc grammar. The reason why foo()[1] doesn't work is because it's a bad programming language, not because it doesn't have a grammar. It has one and it says not to parse that :)
- tomelders 15y agoFrom the comments: "PHP is great for its purpose. Quick scripts that generate web content. It’s even OK for small applications. But just like C, PHP is lousy for the medium to large. Any software project with a duration in months or greater that is entirely in PHP is going to be painful." Like Facebook? Or Wordpress? Or Digg? PHP aint perfect, but it's demonstrably suitable for medium to large projects.
- tvon 15y agoThere is little indication that Facebook isn't painful to deal with compared to a functionally identical version of Facebook built in another language/platform. Because someone did it and is profiting from it does not mean they could not have done it better.
- drzaiusapelord 15y agoI thought FB's troubles were with mysql not PHP. Turns out mysql has some limiting factors.
- Pewpewarrows 15y agoTurns out * has some limiting factors [when serving 1 trillion page views a month]. Replace "*" with any piece of technology on the web stack. There's not a single other company in the world (sans probably Google) that has to deal with performance problems on that level of scale. At that point, I can't imagine anything surviving out-of-the-box. Something has to give, even the language they're using (they're using a subset of PHP that they can run through a custom compiler to C++ machine code, to squeeze every possible CPU cycle out of the servers they have).
- astrodust 15y agoYou can build a Tinker-Toy computer that plays Tic-Tac-Toe, but just because you can doesn't mean you should. http://www.computerhistory.org/collections/accession/102630799 http://www.computerhistory.org/collections/accession/1026307...
- 15y ago
- asifjamil 15y ago"There is nothing more exciting than modifying a file, hitting Refresh on your browser and seeing the result right away" I think this feature is definitely useful, but you can virtually do the same thing in other languages with templating engines.
- tvon 15y agoWith additional setup, yes, but PHP has a fast development cycle out-of-the-box which I think is significant.
- mseebach 15y agoThis mind-bendingly important. In 1999, you could download one single installer on Windows, run it and with literally no further configuration you'd be writing PHP on an Apache/MySQL stack. No other environment even came close at the time and for a long time following.
- j_col 15y agoThis is still the main reason why I use PHP: the development cycle is just so fast, and if you are experienced enough to write good code without anyone holding your hand, you can do great work in PHP in a much shorter period of time when compared to most other platforms (at least the ones I've tried). When people criticise the PHP language I think they really miss the point: it is the PHP platform that is really powerful because of: 1. The shared nothing architecture (it really helps you scale). 2. The rapid development cycle. 3. The portability (Apache, IIS, nginx, persistent in-memory interpreters via PHP-FPM...). 4. The huge amount of native C extensions providing amazing functionality. Sure the language has warts, but who cares when the platform is this powerful?
- ericd 15y agoYep. And compared to Rails, something like mod_php is just so much faster and less resource hungry, it hurts. I use both regularly in production, and scaling the PHP side is almost trivial compared to the rails side.
- kayoone 15y agoYou can do anything web related with PHP, it might not be the coolest kid in town but it gets every job done pretty well in the space it has been designed for. Use a framework like symfony and large scale applications with decent design are no problem at all in PHP. Same is true for Python, Ruby etc though, so just use what suits you best. Comparing it to C ? Dunno, completely different animals. I wouldnt do web dev in C, but i also wouldnt do graphics programming in PHP. Just because they both are not designed with OO at the core doesnt mean they are exactly the same.
- leeoniya 15y agoPHP is fast to develop with, but its inconsistency and quirks make it a real PITA to work with quite often. a good summary of the main crap is outlined well at http://www.phpsadness.com/ http://www.phpsadness.com/
- Peaker 15y ago> PHP is exactly like C. Either you like both or you don’t like either, there is no claim you can make about PHP that can’t be made about C as well, and vice versa * C is fast and has tight resource control * C is portable * C has a transitive (==) operator ...
- dpcan 15y agoI sort-of felt like this comment was added in his post to get the blood boiling a little. I love his other points about PHP (as I too like PHP), but I felt this was one of those bold statements that was a little sensational and attention grabbing at best. I too find it pretty far fetched.
- ZoFreX 15y agoI honestly don't intend this in a mean way (I mostly code in PHP at present), but if you loved his other points you might want to delve a little deeper. PHP is a good enough language, but a lot of what he is saying is either incorrect, poor form, or championing solutions to problems that simply don't exist in other languages.
- rbranson 15y agoYeah, clearly this is a troll blog. Congrats to the troll.
- rick888 15y agoOne of the reasons I like PHP is that it still lets you get to a lower level of coding. Many of the newer languages and frameworks that have become popular in the past couple of years abstract things such as database connectivity away (Django is a good example of this) and it makes it difficult to optimize queries effectively without hacking onto the framework.
- dshah 15y agoMost ORMs (including Django) let you easily drop-down into writing your own custom SQL queries when the need arises.
- rick888 15y agoI've used Django and many others and while you can do this, you end up with code that isn't very clean.
- ch0wn 15y agoDepends on your definition of 'clean'. I think Django found a very solid way to handle raw SQL statements[0]. [0] https://docs.djangoproject.com/en/dev/topics/db/sql/ https://docs.djangoproject.com/en/dev/topics/db/sql/
- epochwolf 15y agoRails has two ways to do this. You can do any select query returning active record objects with Model.find_by_sql("raw select query") And any query with a driver dependent result using ActiveRecord::Base.connection.execute("raw sql") You can shorten the second one to simply "execute" by creating a method to wrap the functionality.
- astrodust 15y agoDon't confuse abstraction and formalization with convention with restricting low-level access. Most ORM frameworks allow you to drop down to direct SQL if you need to.
- 15y ago
- chc 15y ago"I don’t even bother writing tests for most of the PHP I write (obviously, I would be a bit more thorough if this code were destined to be used in a more mission critical web site). Not writing tests is not the only software taboo that I break when I write PHP: I happily mix up presentation and logic all the time. That’s just how PHP is supposed to work" And this is why everybody else hates PHP. It tempts you to write bad code, and so most people working in the language end up doing so. I have to periodically stop myself when I'm writing PHP and make sure I'm not falling into bad habits. It's possible to write good code in PHP, and I know some people who do, but the pull to write sphpghetti is too strong for most. And there is no real corresponding benefit (aside from "noobs who don't care about code quality can still write programs") arising from the design choices that cause this.
- slindsey 15y agoCan you please provide me a resource to learn how to fully separate the code from the markup? I learned web development on ColdFusion then switched to PHP. I certainly understand separation of content from design (HTML to CSS) but I honestly have no idea how to do web development without mixing markup (HTML) with the actual programming. I've done a little C and Java web stuff where my code printed HTML output - ugly. CFML and PHP mingle HTML and code together - also ugly, but better. I can't fathom any way NOT to mix them but would love to have some resources to see what I'm missing. I know there needs to be something better. Thanks.
- lhnz 15y agoHave a play around with a framework such as Symfony [1]. That's the most natural way of learning a better style of PHP web development. [1] http://www.symfony-project.org/ http://www.symfony-project.org/
- eropple 15y agoAny particular reason you're linking to Symfony instead of Symfony2? I find the latter so much easier to read and work with it's not even funny.
- kingkilr 15y ago> PHP is like C In all the bad ways, and none of the good ones.
- peteretep 15y agoI like MJD's quote the best: "Like C without the speed, like Perl without the toolbox"
- keypusher 15y agoYeah... the author pretty much lost all credibility after that sentence for me. If C was a Formula 1 race car (fast, dangerous, designed by the most brilliant minds in the industry), PHP would be a Ford Pinto (cheap, convenient, ugly, and very likely to blow up on you out of nowhere).
- freshhawk 15y agoThere's a regular stream of "defending PHP" posts but they all seem to miss the point. No one bashes PHP because it can't do these things, or that it isn't easy. People bash PHP because there are objectively better languages and platforms out there and objectively bad decisions made by those guiding the PHP language. If you want to defend PHP in any meaningful way then you can't just list things that can be done easily in almost every semi-modern web ecosystem, but actually compare it to the other alternatives and identify when it's the right choice. It's harder but it leads to a blog post that might actually benefit readers.
- skrebbel 15y ago> If you want to defend PHP in any meaningful way then you can't just list things that can be done easily in almost every semi-modern web ecosystem Did you ever read Python's documentation? Or Ruby's? Or Java's? Show me one popular web programming language which has a full page, up to date, with examples and user comments and version incompatibility info, per function. Of course, it's just one point and I otherwise agree with your comment, but it's one hell of an advantage.
- RyanMcGreal 15y agoPython's got excellent documentation, both official and third party.
- mbrzuzy 15y agoIs PHP that much worse where it's worth it to jump onto the ruby ship? I'm just starting to code one of my current projects, but in PHP. Should I consider ruby instead?
- adambard 15y agoHere is some PHP code: $x = "0"; if(!$x){ echo "0 is false"; } If you understand why it's crazy that PHP prints "0 is false" when you execute that, you're probably better off jumping ship now. If you don't, you'll probably appreciate the low barrier to entry for PHP more than any benefit you'd gain.
- adambard 15y agoActually, here's a more insane version: $x = 0; if(!empty($x)){ echo '"0" is empty'; }
- pornel 15y agoempty() is an alias for 'isset($x) && $x', so this example is semantically identical to the previous one (since $x is always set). PHP doesn't have any special concept of "emptyness" to check for.
- NathanKP 15y agoI understand why it prints zero is false, and personally I feel that it makes perfect sense. Indeed I approve of it. The fact that strings can be evaluated as numbers is great for accepting input from GET or POST because it means that there is no need to worry about explicitly casting strings to numbers. Of course, input type validation is still important, and if a variable input by the user is supposed to be numeric, that is why there is the is_numeric() function to validate the type of a variable. But once I've used is_numeric() and know that the string is numeric why should I bother with an explicit strtoint call? I feel that this feature of PHP if used correctly takes away complexity and repetition related to converting strings to integers. In a realistic project the framework for your app should have a layer between user input and your code anyway. At this layer it will be validating that input from the user is of the correct type anyway, and once that variable passes the is_numeric() test the layer can easily cast that input string to an int so that it is the right type for JSON encoded objects or any other output from PHP for other languages that needs to have specific types. Once again, if PHP is used properly, with a decent code architecture this feature of PHP is not a problem.
- plq 15y agome too, i like php. it's a decent templating language with some very advanced features. it even supports namespaces!
- pornel 15y agoIt's an XSS-prone templating language, as the default correct syntax for outputting variables is: <?php echo htmlspecialchars($value, ENT_QUOTES);?> which is far from encouraging safe best practices. PHP namespaces aren't any better: http://pornel.net/phpns http://pornel.net/phpns
- shiflett 15y agoActually, you should also always indicate the character encoding, for reasons I explain here: http://shiflett.org/blog/2005/dec/google-xss-example http://shiflett.org/blog/2005/dec/google-xss-example
- pornel 15y agoYes, declaration is necessary, but not in the htmlspecialchars() call if you're using ASCII-superset encoding (and you really should declare UTF-8, never UTF-7).
- yid 15y agoFrom TFA: > * I have yet to see this kind of universal support for any other language than PHP. Not even Ruby on Rails, let alone Java, is available on mainstream providers, thereby validating the claim I made five years ago that Ruby on Rails won’t become mainstream (I regularly receive emails about this article asking me this question, and I keep responding “Nope, still not mainstream”).* If your provider doesn't support Ruby, you need to get yourself a $20/month Linode box. If Linode and a $20/month price point isn't mainstream, I don't know what is.
- Ixiaus 15y agoYou can do cheaper than that - WebFaction will give you an $8 a month shared hosting account and you can run anything you want! They have a really cool automated setup system for more involved projects like Django/Pyramid/Sinatra/Rails and lots of others.
- yid 15y ago...which leads me to think that the poster is confusing "mainstream" with "GoDaddy".
- masklinn 15y agoOr confusing "mainstream" with "free webhosting by your internet provider"
- cedricbeust 15y agoI'm not. I'm using a fairly "non-noob" ISP (ssh access, crontab, etc...) and they still don't give me access to much more than PHP. I can install Java but I can't even run it as a CGI because of the HTTP request memory constraints they impose. This is pretty standard, I don't blame them for doing this, and I would go with a VPS if actually needed all this. Same for Ruby on Rails, obviously.
- yid 15y agoI fail to see why "my ISP doesn't give me Ruby" --> "Ruby isn't mainstream". To my downvoter, here's a list of "mainstream" providers, at the Godaddy-level, and language support: Dreamhost: RoR, PHP, Perl, Python [1] Godaddy @ $8/month: PHP, Perl, Python, RoR [2] a2Hosting @ $3/month: PHP, Perl, Ruby, Python That seems pretty mainstream to me. [1] http://beta.dreamhost.com/web-hosting/ http://beta.dreamhost.com/web-hosting/ [2] http://www.godaddy.com/hosting/web-hosting.aspx http://www.godaddy.com/hosting/web-hosting.aspx [3] http://www.a2hosting.com/services/web-hosting/ http://www.a2hosting.com/services/web-hosting/
- yuvipanda 15y ago> I write PHP code very sporadically Explains it. PHP is fine if you jump in, write a few lines, and then don't ever have to maintain it yourself. Woe to the guy who does have to maintain it.
- cedricbeust 15y agoAbsolutely, and I'm sorry if my article didn't carry this point across. I would never use PHP for anything big/complex, my post was mostly in response to the universal sneering and mocking that PHP always gets. I think it's unjustified. Since I only modify my web sites a few times a year, I am pretty sure that I would be much more reluctant making these modifications on a RoR app than a PHP one.
- rjknight 15y agoPHP's greatest strength is that it doesn't require OO. Seriously, for most simple web application tasks (and even some complicated ones) OO adds more confusion than it removes, and I say this as someone who certainly sees the value in OO for complex apps. Most web apps are ultimately more like shell scripts or console applications than desktop/mobile applications. It's no coincidence that most of the former are written in C or C-like scripting languages, and most of the latter are written in OO languages running on .NET or Java. Your basic operations are "print some stuff", "read from a file or database" and various sorting, slicing and text-processing tasks inbetween, all of which are done well by PHP, Perl, C and so forth. ActiveRecord, TableDataGateway etc. are great patterns for data access, but sometimes mysql_query("SELECT foo FROM bar WHERE x = y") is just so much simpler that it becomes the better option. The lack of OO makes PHP's documentation much more browseable, and makes code more readable in certain situations. If I look at your code and I see a function I don't know, I just google it. If I see a method invocation on an object, I need to figure out the type of the object (not easy in a dynamic language) and google the combination of class and method name, which often fails to return a result (has anyone ever managed to find anything useful in the Zend Framework docs?). PHP isn't the only data point for this argument - I think it's probably why Drupal handily beats ZF, Symfony etc. in terms of popularity, despite the superior OO architecture of the latter. You can google pretty much any API function and get an accurate result, which you just can't do with ZF (which lacks documentation at the method level, and what documentation that exists is buried in some Doxygen-based site which is made impervious to search by the use of frames). I'm also reminded of Linus's argument against OO in the Linux kernel - when you're all about the patch files, you need clear function names to understand what's going on without massive amounts of context. Drupal's rate of contributions probably exceeds that of other frameworks for similar reasons. Of course, this bias against OO is also what makes PHP a bad choice for certain things, and this is why plenty of devs hate it. I honestly don't know if, in the final analysis, this makes PHP a good or bad choice. It probably depends too much on the problem you're trying to solve for there to be a simple answer.
- jrockway 15y agoWhat's so hard about OO? Instead of string_length($string), you write $string->length. The semantics are the same. If you pass something other than a string to string_length, the results are undefined. If you call length on an object that doesn't do the length method, then you get an error. The attraction of PHP is that it never tells you that you're writing code that doesn't work. The result is a lot of code that doesn't work. This is bad, not good.
- acabal 15y agoI like PHP because it's got a C-like syntax, which is a personal preference of mine. I also like it because it exposes the nuts-and-bolts of web development without any fuss, unlike, say, ASP.NET (though last I touched that was 3 years ago so doubtless things have changed since), and that it has a basic templating system built in, and that it's easy to install and deploy to. It definitely is deeply flawed for many reasons, which is why I'm still looking for my "white unicorn" language: one with a C-like syntax, no fancy templating or ORM magic (just let me print() html), foss, easy to deploy, and with an established community and searchable "recipes" online. Lots of languages fit some of those criteria, but I haven't found one that fits them all.
- ZeSmith 15y agoFor ASP.NET, indeed, WebForms can be a bit violent since it's essentially an abstraction that tries, with mixed sucess, to make you forget you're writing for the Web. ASP.NET MVC, which came out 2 years ago, is much closer to RoR and other similar frameworks, and is a better abstraction in my opinion.
- MatthewPhillips 15y agoI don't think Microsoft is even still developing WebForms (last release is April 2010). Too many aspx sites are written in the old version of WebForms which turned the html output into a horrible and ugly mess. MVC3 is pretty much just as good as RoR or any other mvc framework about outputting clean html.
- jrockway 15y agoUh, Perl? I wouldn't write this kind of Perl, but Perl is not going to get in your way. "use CGI; print html(body(p("OH HAI")))". When you realize that this sucks and you can't maintain it, you'll be able to gradually improve your code. First, you can run your CGI from Plack instead of Apache. Then, you can start using features from a Plack-based framework, like URL mapping. Next, you can move your "print this HTML" into template classes. Then, you can convert these to using TT (or similar), and your app code won't notice. You can start writing unit tests. You can gradually migrate your raw DBI calls to DBIx::Class by using $schema->dbh_do. You won't have to do it all at once and you won't have to break any code when you do. Perl will grow as you do. Or, you can stick to CGI forever. It doesn't care :) It's a great language for starting small and building up "complexity" as you learn more about programming.
- aidenn0 15y agoMy observations for the popularity of PHP are this: 1) It's old. You're alternatives to PHP 12 years ago are all bad. The most popular alternative was perl CGI scripts. 2) Since it's templated, it feels more like markup . Someone with absolutely no programming background can go: HTML -> HTML with a javascript "onclick" handler pasted from the web -> HTML with a bit of PHP pasted from the web -> writing my first original PHP code
- PedroCandeias 15y agoI'm just glad we're at this point where there are so many quality languages and frameworks available that we can fuss over which one is best. That is all I'm going to say on the subject.
- vandahm 15y agoWhere I work, we've standardized on PHP and I have no choice but to use it. It isn't as bad as people say that is! Our organization's product is a large application written in object-oriented PHP with unit tests for every method of every class. As a team, we use continuous integration and have regular code reviews to promote quality. We've done some things that we're not proud of, but on the whole our codebase is pretty clean and elegant, and at the end of the day I'm almost always proud of the work I've done. What worries me about PHP is that innovative ideas don't appear to be coming from the PHP community. They come from Python, or Ruby, or Erlang, or Java projects and are copied by PHP developers afterwards. I worry there's a risk that PHP is being left behind as the developers who solve new and challenging problems turn to other languages. Furthermore -- and this is just my sense of how things are where I live -- while it's possible (and not even difficult) to write quality PHP code, it seems to be difficult to find developers who care about quality. My manager complains about this constantly and I'm inclined to believe him since, when I was a freelance developer, I saw tons of PHP code that was simply and unambiguously terrible. Conversely, a developer who wants to write quality code in PHP has to look pretty hard to find a PHP shop that recognizes quality and values it. I suppose that these issues aren't tied to a particular language, but they seem more pronounced with PHP.
- scelerat 15y agoI submit that PHP's popularity has much more to do with mod_php and its ubiquity across cheap web hosts than any intrinsic merits as a language. As someone who made a good living for many years by building stuff with PHP... I couldn't get away from it fast enough. Rails+Heroku is the new PHP, if you want a batteries-included web framework and easy hosting. Not rhetorical: does anyone here use PHP for starting new projects?
- j_col 15y agoYes, in fact all of my new projects are in PHP unless I'm absolutely forced to use something else (and I say this as someone with years of Java experience and some Ruby experience).
- rogeriopvl 15y agoGotta love these "My tool is bigger than yours" discussions...
- mtogo 15y agoThis comment is almost better than the blog post itself: > But just like C, PHP is lousy for the medium to large. Any software project with a duration in months or greater that is entirely in PHP is going to be painful. Yeah, C is terrible for medium to large projects like, say, Linux.
- pavpanchekha 15y agoC is one of the few languages Linux can be written in. That doesn't mean it's the best for the job.
- rickmb 15y agoPHP's one great strength is that it can be effectively used in a very wide range of applications. But doing that well requires using the language in ways suited to that purpose. The problem with people "defending" PHP is that they often only use PHP for a very specific purpose, and describe PHP from that perspective. Hacking quick and dirty procedural scripts, writing something like WordPress plugins or developing "enterprise" applications with frameworks like Symfony or Zend are entirely different ways of using PHP, usually done by entirely different kind of developers. The unmaintainable crap PHP is infamous for occurs when less than mediocre developers only familiar with one approach apply those limited skills to a project that requires a completely different approach. What the author describes is not "how PHP is supposed to work". It's just one of many ways PHP can work. (And certainly not my way of using it.)
- eropple 15y agoAgreed. The big problem with PHP, as I see it, is that you have to be already very very good with PHP to write a safe, well-performing application in it. The steps you may take along the way to get there may be very scary, especially if it involves other people paying you to do it.
- jessedhillon 15y agoMore than providing any defense or justification for the use of PHP, this article greatly bolsters the opinion that PHP is for noobs.
- tambourine_man 15y agoThe core of C is small enough that you can fit it in your head. PHP has so many functions that it's almost impossible to write it without googling php.net, etc. Not that this matters so much, Google is fast and omnipresent, but in that sense they are definitively not alike.
- ZoFreX 15y agoAlmost impossible? Pop quiz: The case-insensitive version of "strpos" is "stripos", what is the case-insensitive version of "strcmp"?
- simonw 15y agoI'm guessing it's stricmp... However off the top of my head I have absolutely no idea what the argument order and return values for any of those four functions will be without looking them up.
- ZoFreX 15y agobuzzer sound I'm sorry, the answer we were looking for was "strcasecmp" (Sorry if the level of levity is considered inappropriate, but humour is a level 4 defence mechanism and the only way I can remain sane in the face of such things)
- tiwilliam 15y agoStopped reading when I came to: "Sometimes, I don’t even bother editing the files locally and then transferring them: I ssh to my server and modify the files live."
- jarrett 15y agoThe biggest problem with PHP isn't anything built into the language itself, but rather the culture of mediocrity/naivety surrounding it. As at least one other commenter has said, there are disciplined and skilled PHP programmers. If only they were the majority! Sadly, for the PHP ecosystem, a few good apples don't unspoil the bunch. Here are a few ways PHP's bad culture manifests itself. 1. Cargo culting The web is filled with questionable recipes for doing this or that in PHP. I've observed a strong tendency of PHP programmers to approach every possible addition of functionality like this: 1) Google search; 2) find source code that supposedly does what's needed; 3) paste that source code in without understanding it or thoughtfully evaluating its appropriateness. I'm all for learning by reading other people's code. I'm even OK with pasting code when you understand it fully. But cargo culting is bad, and it seems rampant in the PHP world. http://en.wikipedia.org/wiki/Cargo_cult_programming http://en.wikipedia.org/wiki/Cargo_cult_programming 2. Lack of architecture PHP applications often lack a coherent architecture. It's a typical mistake of new programmers--one that I made many times--to think just enough about architecture to accomplish the task immediately at hand. Naturally, this comes back to bite you when you want to extend your code's capabilities. I see this all the time in PHP applications. Consider Wordpress. Its API is a random, ad-hoc mess of global functions. Things that should logically be exposed as objects aren't (like posts, for example). The API for retrieving content is different depending on whether you're in the mysterious "Loop" or not. And so on. A more detailed analysis of the lack of architecture in Wordpress can be found here: http://www.phpvs.net/2009/12/08/an-exercise-in-wordpress-integration-or-why-wordpress-sucks/ http://www.phpvs.net/2009/12/08/an-exercise-in-wordpress-int... 3. Frankenstein coding Similar to cargo culting, Frankenstein coding is when you cobble together an application from a bunch of off-the-shelf plugins or modules. This is a common practice in the Drupal world specifically, but it applies to a greater or lesser extent in much of the PHP ecosystem. There are two major problems with this approach. First, the chunks of functionality you download are not likely to match your needs perfectly, so you're forced to make due with software that's almost what you want. Second, the code quality of these modules is often abysmal, and that means security flaws, among other problems. Sadly, many PHP developers seem perfectly content with this. Even worse, they do this for clients, who get a semi-functional end product at bargain basement prices. That practice gives me a cheap, sleezy vibe, and it doesn't help my impression of the overall PHP ecosystem. The language itself is so-so in my opinion--not good enough to be my go-to language, but not so terrible I'd refuse to work with it. But somehow, probably due to the language's accessibility, the PHP ecosystem seems to have been swamped by coders who know just enough to get by. And that's my real problem with PHP.
- alanh 15y agoKeep in mind that perhaps a majority of wordpress.org sites that have been around for a year or more have been hacked in some fashion at some point, and that the reason is because PHP encourages the kind of terrible code and unsafe-by-default environments that make this possible. Edit For example, I am thinking of how various templating languages, including Jinja2 (for Python) default to auto-escaping strings you're echoing, but with PHP, you by default have to explicitly think about it and call `htmlentities($x, ENT_QUOTES, 'UTF-8')` all the time.
- pale_rider 15y agoWordPress sites get hacked because the owner fails to update the platform or install 3rd party scripts/plugins without any sort of logical research. This can be said about any platform, regardless of the language.
- alanh 15y ago> WordPress sites get hacked because the owner fails to update the platform Why are the updates even necessary? If you are still on Rails 2.3.8, you aren’t getting hacked just because you didn’t move to Rails 3 yet. But the situation with Wordpress & its ecosystem seems waaay less secure by default. > This can be said about any platform, regardless of the language. Not to the same degree, no sir.
- pale_rider 15y agoLast time I checked Rails was not a content management system. A fair comparison would be Drupal, Joomla, vBullentin - anything of that nature - which all regularly release updates.
- alanh 15y agoThose are all PHP based and would seem to prove the point.
- nerd_in_rage 15y agoPHP sucks as a language, but honestly, it's a LOT less painful to develop a working web app in PHP than Java, Python, and just about everything else. Why? There's no deployment issues. There's no waiting for my app server to restart, no delay while a change is detected, etc. You edit a file, click refresh. Flame away.
- rb2k_ 15y ago> Not even Ruby on Rails, let alone Java, is available on mainstream providers Just picking a few of the "big" ones: dreamhost.com: supports RoR hostgator.com: supports RoR bluehost.com: supports ROR hostmonster.com: supports RoR godaddy.com: partially supports RoR (fastcgi) I guess that is simply not true anymore
- perlgeek 15y ago"there is no claim you can make about PHP that can’t be made about C as well, and vice versa." What about hundreds or thousands of inconsistently named built-in functions? C doesn't really have built-in functions, just a standard library that you don't have to load if you don't like it.
- roel_v 15y agoThat's at best semantic nit-picking. You cannot write a useful C program without using the standard library or re-implementing (parts of) its functionality yourself. If for some reason having functions available that you don't use bothers you, you can still easily disable most of them by not loading any extensions; and if it's really a big issue to have the 'standard' functions in php available, you can compile php to not include them. If this is the best example of why php isn't like C, they are actually very similar...
- phatbyte 15y agoMy first web language was PHP, I started working with it 12 years ago. Back then you didn't have Rails, Django, ORM, unit testing (in web dev that is), and javascript was looked as a language to just show popups and have confirm()'s before submitting forms. If you wanted to connect to a MySQL, you have to do it all by yourself, you need to create a database, tables, PKs, connect to database, execute RAW mysql queries, and so on. Form validation ? Yeah right. Back then the include_once() or require() were amazing for separating code. But all in all that mades us learn how things work internally, how HTTP requests work, how SQL works, even why CSRF or XSS and SQL injections are executed. Yes, the code was shitty, it was all over the place, but we learned how a web app works internally. And yet, most developers I know who coded PHP back then are amazing developers today in any web language or framework. Why ? Because most of them learned doing things the hard way. We had to understand how HTTP requests works, how SQL works, etc..etc.. because we didn't have the magic of rails, or any helper for any framework. In these 12 years, web development as grown, a lot, and for the better, I'm currently learning Rails, and I've already done a project with Django and Node.JS . I liked them a lot and they are amazingly well done, I just wished PHP was more OO like ruby or python. However, I laugh at these new Rail/Django developers that joke about PHP code. Most of them start coding jumping immediately into a framework. I bet that most of then couldn't create a simple MVC framework, ORM from scratch, hell, even a simple security CSRF would be a pain without "gem install <whatever>". You see kids, PHP was like our first GF or our first car, where we tried stuff, made us cry (in a sense), and helped us grow and mature as developers, for those who wanted to grow that is. Now you have lots of languages for web dev, but back then PHP was the thing. I still believe that PHP is a very cool language if done correctly, I wished tho, that it should be rewritten to be more OO. But if one thing I learned from all of these years is that, it's the developer who makes quality code, not the language. Unless that is, you are using a framework who basically demands you to do things the way it wants, and puts a lot for magic so you don't bother with "boring" stuff. But in the end of the day it's not your code, it's theirs. So my advice for new dev is, forget frameworks, and learn the hardcore way, then pickup a framework you love and go with it, either PHP, Ruby, Python or whatever.
- relix 15y agoI don't think it's a good idea to advice newbies to learn the hardcore way. I'm exactly like you, started with PHP, had to do everything manually, etc... except I have a different opinion. The reason you and I and all the others like us put in so much effort in solving problems in PHP like CSRF, XSS and SQLI was because we were passionate enough to learn about that and then implement solutions for it. Developers who don't care about security measures like that - they're the ones who store plaintext passwords, still - won't care either way, no matter if they're using Rails or PHP. Frameworks like Rails solves it for them, but if it weren't for Rails, their apps would have all these security problems, and they would only be addressed once disaster strikes. Those that do care will be passionate about their work. They are the ones that read up on XSS and CSRF out of interest, not necessity. I'm sure they look at the generated HTML source once in a while, and then wonder why they add that token there. Using Rails, newbies are exposed to the solutions from the start, encouraging them to learn about it. As a PHP newbie, you're never exposed to the problem or the solution, until you start reading about security on your own or you get into trouble.
- iterative 15y agoYou know who used php? Hitler.