Hacker News new | past | comments | ask | show | jobs | submit login
Taking PHP Seriously [pdf] (raw.github.com)
129 points by memla on Sept 28, 2013 | hide | past | favorite | 148 comments



At this point we almost need to stop saying facebook programs in PHP. I know this was defending PHP, but look at what is happening. Facebook ( big engineering firm, lots of developers and resources ) could not get php to work for them short of rewriting the core (HPHP ) and then adding on features to the language that most other languages have determined are useful enough to be baked into the language.

Here is my TL;DR of this article. PHP is bad we all know this and accept it. Facebook has made it better by keeping most of the syntax and chucking everything else out the window. Run your stuff on HipHop ( unless you need extensions in which case your OOL )


Video of the talk is not up yet, and it's a little cryptic with just the slides. But one of the points I was trying to make is that PHP actually makes you more likely to be successful than a lot of its competition. The lolsy stuff on "The Case Against PHP" slides is all you ever hear because ... well, because they fit on slides. They're immediately, obviously weird. But these problems are shallow. There are deeper properties of the language and its interaction with the environment that overcome those problems, and then some.

Also, it's a little obscure for languages like PHP where we're unused to making architecture/implementation distinctions, but if HHVM is good then PHP is good. It runs the same core language as php.net. To the extent we don't, it's likely to be a bug these days. I think HHVM is a better implementation of that language than php.net, but I am biased, and that isn't the point of the talk. We're also chipping away at running other popular programs, extensions and all: http://www.hhvm.com/blog/?p=875

Edit: transposed sentence


could not get php to work for them short of rewriting the core (HPHP )

I've heard this argument before, but it's important to realize that Facebook was able to use standard PHP up until the point when they had roughly 500 million users. Unless your site has a half billion users you can't compare your use case to Facebook's.


They're making three sorts of changes: 1) removing/restricting the footguns in the language 2) adding interesting features taken from other languages (typing, traits, etc). 3) creating a new VM with better performance.

As far as I can tell, only 3 is obviously something that only affects whether you can use the language once you have a certain number of users. The first two are really about changing the language.


Maybe I should have expressed myself more clearly: The comment I replied to seemed to indicate that PHP must be bad since Facebook had a need to change it. My point was that, given the fact that Facebook has way more users than other sites and mostly serves non-cacheable pages, their needs are different than the needs of 99.9999% of other sites in the world, so the fact that they were forced to change PHP doesn't say anything about PHP's quality as a language.


The # of users really says nothing about how expressive the language you're programming in is.

And if we're talking about consumer products like facebook, it doesn't even say anything about how fast your programming language is since performance is dominated by database access time.

At best, we can try and claim that Facebook found PHP to be insufficiently expressive/safe/suited for them once they had X number engineers making Y number of changes per day.

Maybe they really could "move fast and break stuff" with 200+ engineers trying to commit to a vanilla PHP codebase.


Speaking as someone who works on a 2 million user enterprise app with standard PHP, i would have to counter that: 1) the footguns are easy to sidestep once you know them and are gradually getting removed, 2) standard php has traits and strict typing, but the typing is not for primitive types (which is what Hack adds) and 3) in nearly a decade i have had a single feature where i could have really used a faster php, whereas in practice my performance issues all come from the Oracle bottleneck because php is so easy to parallellize. Facebook could run on standard php, it would just require more hardware, and since releasing hhvm php has gotten a lot faster without breaking backwards compatibility.


I'm curious on how many servers does it run :)


PHP(.net) doesnt have strict typing ,but type hinting, which is not the same.


It does have strict typing with objects, but not literals.

If I make a function meow(MyClass $meow) { } it will throw errors if anything other than a MyClass is given to it, including NULL.


You are wrong , it has type hinting , not strict type checking. You can alias types, there is no hard types in PHP except for arrays. Your function signature check the name of the object in the namespace , not it's type.


function meow(MyClass $meow) { }

This will only accept an object that is_a MyClass. It can either implement an interface MyClass, extend an abstract MyClass, extend a regular class MyClass, or be the actual object MyClass.

Namespaces have nothing to do with this, other than you being able to use the "use" statement at the top to alias it.


they most probably would have made similar changes if they had used ruby or python. They have very specific problems brought on by massive scale which will expose the flaws in any scripting language.


Yes and no.

As a matter of fact Facebook would probably have run into the same problems if they had used Ruby or Python. These problems are problems of massive scale most of us will never face. Twitter had problems running on Ruby/Rails and i bet theres a case to be made for Python too. All this says is that at the scale level of facebook you will encounter the limits of dynamic typing scripting languages, but its not a problem with PHP per se and also not a problem that should hold anyone back from choosing php/ruby/python because its premature optimization.


Both Youtube and Disqus (just to mention bigger names) started delegating heavier tasks to Go, instead of Python. So yes, this case can be made for most high level languages.


    >At this point we almost need to stop saying facebook programs in PHP
This isn't the first language-incompatible change they've introduced - see XHP, which used to exist as a Zend extension(?) and is now rolled into hiphop


Judging by that TL;DR people would think that there's an article with pages upon pages of what Facebook decided to eliminate from PHP, and not to make it easier but to make it possible to mantain their codebase. No such thing can be found in the provided PDF.


They've added static typing, return types for functions, and a few other things. I believe the premise of the talk is that it's still possible to use everything else available in PHP (traits, generators, namespaces, etc.)


Tell Facebook that. They are the ones talking about it still.

Also, your TL;DR is a flat out lie.


Another hard example: A start up wants the cutting edge tech so they use hphp. The company ran out of money before it finish complied.


Adams actually makes some very valid arguments in this PDF. People like to argue the superiority of languages, but at the end of the day if the result in PHP is the same as it is in Ruby & Rails, Java, .NET or whatever, does it really make what the language is? Another good point is the efficiency of a developer working in PHP. The language is easy, it's so easy to be a PHP master after a few years working in the language. It's easy to find super-talented PHP developers compared to any other language.

I like the idea of opt-in typing for PHP via Hack which you can enter by beginning your PHP code with <?hh — Facebook have essentially taken everything that is wrong with PHP, every complaint that someone has ever published in a blog post or bug report, forum or IRC channel and built it into an improvement of the language.

PHP isn't going anywhere. It might be one of the oldest web languages, but I think the PHP space is starting to get better with Facebook's contributions to the language, Laravel 4 being a solid PHP framework and we can't forget that most Yahoo! products are built using PHP as well (even the recently acquired Tumblr is coded in PHP). Flickr! is probably one of their biggest PHP applications.

Event hough Facebook appear to have resolved the many complaints and problems of PHP, I am sure people will still find a way to complain about the language that powers most of the web...


Are the complaints about PHP even controversial? The built in library functions are a mess, and mostly terrible. The syntax and basic language are overly verbose and have layers upon layers of cruft. The type and object systems are grafted on, and have so many gotchas and inconsistencies that it takes many months to understand enough of them to be very productive in the language. The aspects of PHP that were intended to make it simple (like pretending types don't exist) actually make it more difficult to reason about precisely. I don't think anyone who knows anything else would ever choose PHP for a fun personal project.

Despite this, there is nothing in PHP that prevents you from doing the thing you want to do, however you want to do it. As projects become larger and involve more time and people, the fine grain of line syntax fades out of view, and all that is left is the large scale design decisions, which are similar in any language. And this is what ultimately determines the technical success or failure of software.


I code in Python, BASH, C, and PHP on a regular basis and still strongly prefer PHP for everyday coding and hobby tasks. I even prefer to create command-line scripts in PHP (though will switch to Python if it's large to begin with). For me getting Flask to work properly under NGINX + uwsgi was such a hassle. Having to tell it what module, and hooking things up to touch versus just passing to PHP under fast cgi.

To be honest, PHP is really just simpler, less hassle, and if you know what you're doing things come out structured well. Just stick to classes (Including statics! There shouldn't be a define() anywhere.), use namespaces, use composer (I've come to really like it), and use a coding standard.


In what ways is PHP less hassle than Python? I don't understand this argument.


Deployment, for one. sudo apt-get install Apache and PHP, then edit the Apache config to say, "use this directory." I love Django and Flask to pieces, but deploying a Python app is like building a hovercraft compared to PHP.


I have no problems deploying a django app with gunicorn. It's a simple command line statement, and deployment is always an intricate thing, unless you don't have to worry about ssl certs and secrets and keys, and managing access, admin pages, etc etc.


Which you usually don't for fun personal projects.


I'm going to say it, better documentation. I don't know, maybe it's just me, but I find it takes me significantly less time do find out how to do something in PHP, or a PHP library than in the corresponding Python. Though, there are obviously exceptions to this.


Ooh, yes. While PHP's docs sometimes promose horrible worst practices, they are more detailed and fleshed out than Python's.


Abstract classes in Python are kinda bolted on http://docs.python.org/2/library/abc.html

They're native to PHP http://php.net/manual/en/language.oop5.abstract.php


Abstract classes are unnecessary and "unpythonic", if you will; there's a lot of other preferred patterns in Python for that use case.


I don't think it's less of a hassle than PHP, but in the context of web development, it is. In PHP, your development environment is often very similar to your production environment.

I think the primary difference is PHP is web first: it was designed to be a language for the web above all. Everything else is tacked on. On the other hand, Python is useful for a whole array of problems and a website is just one problem you can solve with it.


> I don't think anyone who knows anything else would ever choose PHP for a fun personal project.

I would. For every job, a proper tool. If my project is client-side heavy and only needs a thin layer between the client-side and the database, I'll pick PHP. The code I would write in PHP would be minimal and I would get it up and running very quickly.

If I'm writing something substantial on the server-side, then yeah, you may want to consider something else.


I think it's exceptionally easy to become productive in PHP quickly and to reason about the code despite all the warts and gotchas. The good points about PHP raised in the slides (statelessness, etc.) hugely simplify thinking about code, offsetting the bad stuff and then some.

Doesn't make me want to give up python or node, but these are strong points in PHP's favor.


But with so much frameworks around it is a relief to have the complete control and library support. I am talking about plain PHP.


> People like to argue the superiority of languages, but at the end of the day if the result in PHP is the same as it is in Ruby & Rails, Java, .NET or whatever, does it really make what the language is?

At the end of the day, every program is a stream of bits too. That doesn't diminish the importance of programming languages as a tool for reasoning, managing complexity and avoiding common mistakes.

As the industry shifts from deliver something that sort of works to deliver something with these assured characteristics, programming languages designed around enforcing desired qualities will be of immense value.

> Another good point is the efficiency of a developer working in PHP.

Compared to what? Depends on the developer and problem domain.

> The language is easy, it's so easy to be a PHP master after a few years working in the language.

You can master any language after a few years.

> It's easy to find super-talented PHP developers compared to any other language.

Data?


Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR.

As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many awesome programmers than languages such as python.


Methinks the argument that PHP encourages shitty programming has been effectively countered by the amount of crap legacy Ruby code that has appeared several years since Rails became "hip".

It should be quite obvious to anyone by now that when it comes to shitty programming, language is negligible factor once a language has hit the mainstream.

But I'm pretty sure 5 to 10 years from now someone manages to argue that Ruby is crap, Rails is to blame for encouraging a generation of developers to write bloated controllers full of spaghetti code, and that this attracts shitty programmers incapable of understanding software architecture.


I already start arguing along these lines now - starting with the refusal to define even semi-stable interfaces across versions of a library.

Instead of relying on actual reusable building blocks, you're expected to build specific versions of ruby interpreter and libraries for every project.

Imagine having to cope with just ever so slightly different (but certainly incompatible) philips screws whenever you want to affix one physical thing to another.


If I'm a least-common-denominator web developer and I copy and paste some PHP code into a project from a google search, and I copy and paste some Ruby code of similar origin, what are the odds that each has a inobvious flaw?

Or much worse what are the odds that if I'm an average developer and am picking a random feature from each language's standard library, making care to read the docs before using it in my application that I've still introduced a bug? (Consider that maybe I'm dealing with things that were considered strange and new when most of PHP is still from - like character encodings - particularly character encodings that differ from the system I'm running in).

Most languages can be CGI-style executed by an httpd with shared-nothing, but can also start up and be a long-lived stateful daemon. I don't have to decide between putting a square peg in a round hole or throwing my code away to learn something entirely new if I realize I need the latter part way through a project.

PHP comes with a excessively large (but strangely CGI/HTTP/HTML/SQL-obsessed) standard library littered with footguns, and for most of its life has not had a common pattern for reusable modules, and has not had a good bundler for shipping reusable modules or making working with C extensions easy - and as such few people bother reimplementing functionality from core outside of what's been provided there (which is all set in hard clay), and when they are forced to tend to do so in (plain-ole-interpreted) PHP and don't generally package it up for reuse outside their own projects - a practice much more common outside PHP-land.

Case in point (goddamn strlen, even): https://api.drupal.org/api/drupal/includes%21unicode.inc/fun...

Some of that is changing in recent history (as in well after other languages figured these problems out) with PSR (design for reuse) and Composer (bundler) but it's slow moving and the latter still won't compile C extensions yet: https://github.com/composer/composer/pull/498

Plenty of this could be solved in PHP, some of it already is if you have the luxury to work with a tiny subset of PHP projects, but the practice in PHP seems to still mostly be to have it piss in your face and believe that it's raining. People are in a rut of tradition or simply don't expect their tools or libraries to be good - and I've spent the last 6 years working with PHP (several products, several teams) and wondering where I can get some of the Koolaid that my colleagues are drinking.


The linked article explicitly states that the author has found (albeit anecdotally) that good engineers are very very productive in PHP. I've found this myself as long as you don't go writing code that sits in PHP's "hmm, what'll happen if I do this..." area.


AFAICT, "good engineers are productive in X" doesn't imply that they wouldn't be yet more productive in Y.


Also the Facebook mantra being "move fast and break things" (that anyone working with their API appreciate), it's easy to have a high productivity in most languages.


> Most of the criticism of php seems to contrast it with a language plus a framework. If you really want to compare, compare php with ruby or python, not Django or RoR.

Why? What difference does that make as a programmer using it? If another language is more modular, and lets libraries handle things that are baked into php, isn't that a good thing?

> As for php encouraging shitty programming, a good bit of that is that so many more people program in php because its easier to get started with. This does not mean that just because php attracts shitty programmers that it doesn't have more or many awesome programmers than languages such as python.

Maybe not, but it makes it harder to hire the good ones.


I think it is fair to contrast PHP with RoR or Django, because it was built specifically for generating HTML. Ruby and Python are general purpose languages that do many more things than generate web pages. No one writes iOS apps in PHP but they do in RubyMotion. No one writes high performance Math routines in PHP but they do in Python.


This is my biggest gripe. PHP just does one thing. You can't really use it for much more then building web pages. Yes, you can use it for scripting but Ruby and Python are much better at this.

You have things like Rubymotion(to build iOS and Mac apps), which I'm really liking. Opal which translates Ruby to Javascript. You can build Android apps with Ruboto. You can run Ruby the JVM and call Java libraries. You can run Ruby on the .NET runtime(Iron Ruby). You have a really good Web framework called Rails. Most other PHP frameworks just copy Rails, so why not just use the source. You can build games for iOS using Joybox(library for Rubymotion).

So from a business prospective we chose Ruby because we can do pretty much everything in Ruby. We rarely have to use anything else. From command line applications, to web, to iOS, to Android, to reporting, etc.

PHP, well, you can output HTML, or JSON.


> Most other PHP frameworks just copy Rails, so why not just use the source.

I can't speak for anyone else but for myself regarding this but here we go. I have 12 years experience with PHP, it's my primary language, I know it's got pros and cons, I accept it for what it is and work around it. I know Python is better in terms of standards in languages. I know PHP started out as just a few tools and morphed into a language. But here's what's keeping me from switching to Python or Ruby, or heck even Node.js.. Experience...

Yes I can learn a new language basics pretty easily, but am I gonna be able to write a complete app in say RoR with very few google searches or even looking at the manual as fast as I can in PHP? No... I have been playing around with node.js for 2 years now, long enough to know it pretty well, and yet I can still code circles around node.js with PHP.. 12 years using this language as a primary, it'd take me at LEAST 4 years to even get close to the scale of how well I can code in PHP.

It's just not feasible for me to just up and leave PHP for something "better" based on a few cons and other peoples opinions.


I think PHP is good for some stuff definitely, and if you know it then by all means use it.

> Yes I can learn a new language basics pretty easily, but am I gonna be able to write a complete app in say RoR with very few google searches or even looking at the manual as fast as I can in PHP

That's debatable. I saw someone finish and sell a property management web app in Rails, without knowing Ruby and next to no knowledge of Rails. I wouldn't recommend it. Rails just gives you a lot of things for free. This is getting to much into a framework vs language thing, which I don't like.

I was just making a case for Ruby as opposed to PHP, especially if your job involves more then just web stuff.

As far as PHP frameworks copying Rails, I'm pretty sure that's just accepted as fact. If you don't use frameworks then that's cool.


PHP is only meant to do that one thing. It's not really fair to gripe about it not serving a purpose it was never meant to serve.


Same could be said about Ruby. PHP and Ruby are both "General purpose programming languages". I'm not sure Matz saw creating iOS apps when he created Ruby in 1995. Sure it's not fair to gripe about the language. It's not the languages fault, you can only do one thing with it, it's the communities.


Before this turns into a recanting of the points in the "PHP is a double-clawed hammer" post again, I would like to remind people that PHP still has a place in the business world that nno other language has stepped up to fill.

http://blog.samuellevy.com/post/41-php-is-the-right-tool-for...

Please stop complaining about how horrible PHP is if you don't use it or have. intentions to replace it.


I couldn't agree more.

Having worked with clients that publish thousands of articles of content per month the best solution for the job at the end of the day is still WordPress. Have a client that needs an online store? Magento (both of which are built in PHP).

Development shops don't have time to custom build CMS's and eCommerce solution because their clients don't give a shit what language or framework their site is built in.

Show me a CMS built in ruby, python or javascript that comes anywhere near WordPress and I'll gladly switch. Unfortunately it just doesn't exist. Like you said, PHP has its place and until something better comes along stop complaining.


In my experience Spree is better than Magento for most smbs. You are right,however, there is no replacement for WordPress and its ecosystem. Ghost looks interesting, though.


Also, as easy as PHP to deploy. That's a big matter. The "save and reload" workflow, as said in the slides, is really a big point.


I actually feel the same way about "classic" ASP. Yeah, it wasn't pretty. But for simple CRUD pages of the day, it was damn simple and you didn't need ninjas or rockstars to get stuff done.


I remember asp classic. It was the defacto standard for programming on the web, until something better replaced it. That something was PHP.

PHP means access to easy to install, ready to go software, which meets 95% of the needs of small businesses. I would love to see that in python, or anything else, but it simply isn't there. The most widely used python CMS? Plone. It's massive, hard to maintain, and far from easy to install or host.

I've been on and off working on systems like WordPress for pyramid/python for a while, but it's a massive project. One day I might finish it...


I've used php since v3, in its non-OO days. Coming from perl, that fit nicely. Today, I still avoid OOPHP and continue to write procedurally. The convenience of web-oriented functionality, broad deployment, and soft typing is basically unparalleled, although writing this way requires a bit of discipline. It's also a surprisingly good fit for a lot of server side code if you scale beyond a merely web-based execution model and have existing libraries. These days, I generally avoid perl if data structures are required, and despite dabbling RoR-esque frameworks feel overly constraining with regards to execution path control: I don't want a controller and additional layers of abstraction, the web server does that already!


You just asked for trouble with that last statement lol But I agree, I don't get why people want to force you to do something else, if what you do works fine for you, your productivity and the product you are delivering.

I use php since v3 as well, when I joined College back in 2001, in my first programming class, the professor told me PHP was cr@p when I told him that was the language I was more proficient with. I didn't listen to him... PHP was paying my bills since before I joined the College.


Agreed. There are a few things which are stateful and are therefore made easier/better by OO, mainly DB connections. For everything else, we mostly use classes as namespace (pre-5.3) with lots of static methods. In general for backend web it's pretty silly to spend a bunch of time building up stateful objects when your real goal is usually to load up the subset of information the user needs right now, return that and die as quickly as possible.


The problem with static methods is that they make testing nearly impossible.


Hmm, how so? In general it seems to make testing things easier since nothing is carrying around state; a static method with the same parameters is going to run exactly the same way every time no matter where or when it's called.


You are unable to properly mock static methods. So, for example, if you have a AuthorizeNet class that has a static method ::submit(), if you test the code then every single time you run it you're pinging Authorize.net's servers, which opens you up to a world of hurt.

Properly mocking methods allows you to get rid of this unknown and say, "The submit() method will return an array of this specified data" without Authorize.net ever getting a ping.

With static properties, the problem is that they do have memory. If you change it in one place in your codebase, that static property will then be changed across your whole codebase for that execution, even if you have multiple, separate object instances.


Perhaps I'm missing something, what about static methods prevents you from having a mock AuthorizeNet class implementing the same interface but with a submit() method that just returns fake data? Perhaps there is something specific to the testing framework you use that makes this clunky?

As far as static properties go, if you're mucking with those you're back into the world of storing state, which OO is more suitable for, but the whole point is to avoid doing that wherever possible. :) What I was getting at before is that we really use a mixture of both real OO and procedural with class-namespaces-static-methods wherever each thing makes sense, but given the nature of what most backend PHP is trying to accomplish, the latter ends up being the majority.


In this case, you are probably just using classes to emulate namespaced functions [1], the use of 'class' is confusing to oop programmers, the code does not have classes, just the word class.

Like php code, php itself is often confusing and hard to decipher, currently I think it of it as a C dsl for web stuff that people mistake for a high level application framework.

Like C, many people learn basic syntax and functionality in school or as a side project. Unlike C, people believe that that their skillset is the one required to build a complex server side application combined with a web ui.

If you realize the mismatch and account for it, you can build great php websites. The problem arises when people assume they are getting a 'faster/cheaper' .Net/Java stack and start to hire programmers into that structure.

The net result is a clash between people that are using PHP as intended, and people that have been subjected to the misuse of the php.

1. http://stackoverflow.com/questions/5647598/cannot-import-use...


I am completely against create actual files to make mocks.

I use PHPUnit, the de facto standard for testing php code.

To create a proper mock in it, you use getMockBuilder()


Why can't you use getMockBuilder() for static methods? (I don't know PHPUnit so maybe it's a stupid question.)


These tools only work when:

1) You've implemented dependency injection, or

2) You're using a container

For example, in PHP you can't mock something like "$foo = new Bar();". The code is right there, it's saying exactly what it wants, you can't return a fake class (unless you do some ugly magic).

However, you can pass in an object that is_a Bar, either injecting it via DI or storing it and then retrieving it from a container.

With code like Foo::Bar() - that's it. You're tied to the Foo class, Bar() method and you can't change a thing about this.


Procedural testing isn't hard.

All that dependency crap is only a result of your AbstractTestingFrameworkMethodFactoryClassMockMethodGenerator() and similarly useless abstractions, anyway.

A simple module system can be implemented in a single function and referenced from test code as easily as:

test_requires('module1','module2');

Purely procedural tests are as easy as:

assert_equals(function_one('example_input'),'expected_output'); assert_not_equals(function_two(true),false);

Full featured test framework:

function assert_equals($a,$b) { return $a==$b; } function assert_not_equals($a,$b) { return $a!=$b; }

(Edit: I don't believe I missed the point - 'dependency injection', a recent term in PHP, essentially means tightly coupling to an entire DI system instead of directly to a single dep as demonstrated above. Either way, loose coupling is a concept to strive for as far as reasonably possible - not an absolute requirement. If your code requires something else, then it requires something else. The solution is not to create a new AbstractPretenderOfTotalWorldVisibilityEvenThoughControlFlowIsNowAllOverTheShop() After all, if you carry that tight coupling argument further you could claim that by virtue of writing PHP at all you are tight coupling to a certain, if broad, class of processor architectures. There has to be a limit somewhere! Mostly, that's determined by legibility/maintaintability and programmer time, not by abstract measures of correctness.)


I think you've missed the point. If your procedure calls other procedures, how do you test its functionality individually? How do you know if the problem exists in the procedure itself or one of the procedures it calls. Without DI in some form you are stuck with your procedures being tightly coupled together.


You can still mock the Foo class... by using class_alias.

Don't tell anyone else, though :p


Can anyone please point me in the direction of an open source project on Github that can showcase to me the 'elegance' of all these other programming languages that have the scale and adoption of some of the more well-known PHP community pieces?

I feel like so much of the bias towards PHP is either an unfair comparison (language to 'rails') or a bad taste left in the mouth because the person worked with a nasty domain specific language like Wordpress, Drupal, Magento, etc.

PHP is like pop music; there is a lot of it and 'true' artists think it's beneath them. Nevertheless the public demands and craves it, and most of the big web applications that are open source run on PHP.

If you feel like PHP is a blight on the world, by all means go out there and disrupt the community by launching something that gets widespread adoption the way PHP software has.


My personal bias against PHP has been born out of every single PHP project that I've encountered has been horrible. Everything from simple one page apps to complex projects has just been an unmaintainable mess.

Several years ago I was told to use Magento on a project. Great, Magento is a mature PHP app and I'll get to see some great PHP code. Nope, I was horrified by what I saw and dreaded coming to work everyday and having to deal with that mess of a system.

I have a hard time getting behind a language that everyone uses but no one uses well.


> Can anyone please point me in the direction of an open source project on Github that can showcase to me the 'elegance' of all these other programming languages that have the scale and adoption of some of the more well-known PHP community pieces?

Just look at MoinMoin's source and see how much more elegant it is than MediaWiki.

> either an unfair comparison (language to 'rails')

Why is that unfair?

> a bad taste left in the mouth because the person worked with a nasty domain specific language like Wordpress, Drupal, Magento, etc.

If that's how PHP is used in practice then it's fair to complain about PHP.


> Why is that unfair?

Because PHP isn't actually used like that. Most engineers use frameworks (like Symfony, Zend, Yii, Cake, Laravel etc.) or at least components of these frameworks if they work on something very complex. NIH is a thing of the past.

> If that's how PHP is used in practice then it's fair to complain about PHP.

If shitty developers use a language then it's fair to complain about said language? Really?


I don't take php much more seriously than I take pop music. They both exist. At one point in my life I enjoyed them both immensely. Now I have chosen music that better fits my tastes and solutions that better meet my needs.

I don't choose my music by popularity, and won't try point you to popular repositories. You need to look at your needs, and decide what works for those needs. If that is php, that is great. No need to look further. If php doesn't cut it for you, you will have to decide what you need and find a solution that works for that.


I feel like the reason you don't see a web app development model that takes from the best ideas from both PHP model and the Rails/Django model is because by the time you've been exposed deeply enough to both of these approaches to truly understand the benefits and flaws of each you are way too cynical and burnt out on the idea of tooling around building "the next big web framework." Instead, after watching trends come and go, you just take whatever you can get for free and go out and solve real problems with it.


I'm preferentially a Python programmer who is currently working on a large well-known high-Alexa-ranked website that uses the LAMP stack. The site has been around for a while and is a behemoth, so I understand why it has stayed with these technologies despite the fact that there are many people on the project at this point who'd prefer otherwise. There are both ugly workarounds and rambling boilerplate in several places due to limitations in both PHP and MySQL, and there are also other ugly portions of the codebase due to inexperienced developers or bad legacy decisions that haven't been fully refactored (not the fault of PHP or MySQL). However, there is also a good deal of work that is well thought out and architected so I no longer have as many qualms about PHP as I used to (that I now realize was due to being thrown into codebases that were just a mishmash of crap... there do seem to be more of those in PHP than in other languages, but that's just my personal exposure).

All the same, if you're not inheriting a legacy codebase, I don't think there is any reason to use a LAMP stack on a greenfield project that you will be creating tomorrow. There are just too many better alternatives out there.


    > Facebook’s PHP Codebase
    >  x * 105 files
    > y*107 LoC
    >  10 releases per week
    >  Anecdotally, good engineers are astonishingly productive in PHP
Erm... are you kidding me? LoC != productivity, not even close. And it goes downhill from there :( I really, really don't want to rail on PHP (people do that enough, it gets old, yada yada), but you're kinda asking for it here. The only useful point made is about state, although that's a double edged sword.

...Fuck it, I'll rail. It's 2013. Do yourself a favor. Use something better than a horribly inconsistent glorified cgi script.


That's a very unfavorable reading of that slide. Who are you to say they are wrong when they talk about their own anecdotal experience?

Speaking anecdotally, I got exposed to PHP before I did to Python. I tried Python after hearing how much more amazing than PHP it was. I understand why people say that now, because Python has a "flavor" that I suspect most programmers find more pleasing. I also learned another thing: I am not more productive in Python than PHP.

PHP, like JavaScript, is a language constructed out of good parts and bad parts. They both suffer from the same ailments. It is painfully easy to construct code examples of their horribleness, there are mountains of bad code floating around the internet, they lack essential facilities like strict typing, many facilities that they do provide should be carefully avoided, and the overall flavor of the language is just plain weird. However, PHP, like JavaScript, allows you to be remarkably productive.

JavaScript got out of the doghouse when Douglas Crockford wrote his book and converted the JS community to the jslint style of programming. JavaScript didn't change, but the perception and practice of it did. I think PHP needs a similar champion who is willing to say: PHP can be a good and proper language, provided you use it correctly, and btw here is a tool that tells you whether you're doing that in your code.

I am a PHP programmer, and to your high and mighty attitude I say: screw that. There's nothing wrong with being a PHP programmer.


Sorry. I got bitter there at the end, it was uncalled for. I spent 3+ years as a PHP programmer, there's certainly nothing wrong with being a PHP programmer, but it's hard to argue that in 2013 it is still a good and productive platform to learn. It pains me to see newcomers starting out by learning PHP, they are essentially shooting themselves in the foot for at least a year of their life (if they are going to be a professional web dev). I was pretty productive at PHP, but only because I cut my teeth for years writing shitty cgi-style PHP scripts, learning the abortion they call their stdlib, then using PHP's OOP crap and finally using frameworks like CI. Imagine if I had spent that time writing ruby. By the time you get the whole way through, you realize that your "high-level language" should do work for you, not the other way around. I think what it comes down to is that PHP does not mandate good design patterns because it cannot even decide on one itself. Once I understood this, the language was forever tainted.

I think the only reason PHP is still relevant is because it's so damn accessible (kinda like w3schools), every shared hosting provider under the sun gives you apache+php, and when you're starting learning web programming shared providing is the way to go.

Why do you say php and Javascript suffer from the same ailments? They suffer from a few of the same ailments, like a crappy/confusing stdlib (although you don't see mysql_real_escape_string in javascript's API) and funky invisible type coercions. Lack of true OOP in javascript, though confusing to beginners, is a design feature as far as I'm concerned, prototyping gives you the tools to implement OOP however you like. But javascript has had a known design pattern from the beginning, which is very powerful and useful once you learn it. I strongly doubt a (another?) phplint at this point would change anything.

As for the "anecdotally" slide, I read the last statement as a conclusion of the previous stats, which didn't make any sense to me. Either I am completely misreading it or you are taking the phrase "anecdotally" far too literally.


Please don't flame war. If you do not like PHP do not use it. Don't force another language to someone else's throat.


Idk about you guys but I love PHP. After using new technology for Web Development PHP makes me feel nostalgic. I really enjoy PHP's ease of learning for Web Development. It's easy to understand Databases and Server-side programming using PHP than it is using Ruby on Rails, IMO It feels like magic using Ruby on Rails.


This was an interesting talk. My own interpretation was that PHP's strengths were claimed to be:

1) State => because endpoints have no persistent state

2) Concurrency => because there is no concurrency model

3) Transparency => (1) + (2) + fast reload = easy to understand

These combined give the language nice programmer "ergonomics" (Keith's terminology). It also limits the collateral damage any particular change to the codebase can have which allows Facebook to more confidently deploy multiple times a week.


I think PHP's strength is that the default way of how sessions work makes you intuitively build shared-nothing architectures that parallellize easily and have session data that is hard to corrupt. Sessions are locked at the beginning of the request, and the changes are committed atomically at the end of the request. The next request by the same user is blocked until the session is unlocked. This means that any error causes a rollback to the last known valid session state, and that it is basically impossible to have concurrency bugs (though obviously a PHP server can handle more than one request at a time if they're coming from muliple user sessions). A PHP app that gets an error will typically recover just by pressing F5, whereas in other platforms often you have to log out to throw away corrupted session data. I had little appreciation for this myself until the PHP app I work on reached the point where it had both a large codebase and a large userbase.

Remember also that a large part of the reason why facebook won over its competitors (friendster and myspace) was technology. Both myspace and friendster had trouble scaling up their featureset at the same time as their userbase, whereas facebook pulled it off relatively well. It's hard to know without inside knowledge whether PHP had anything to do with that, but it obviously didn't prevent facebook from winning.


Indeed, there's something to be said about shared-nothing. Lua takes the cake in that since it can be so easily fit into so many nooks and crannies.


It's a strange, strange world when your code has more gravity than the language it's written in and you start warping your language to fit your view of it.

I'll be the first one to take a swing at PHP, but Facebook has done some awesome things with it. I used to program in PHP and it does have some really nice bits...I mean, it's hard to fathom not waiting for my container to start anymore and go back to the days of save/reloading.

Cool. Nice link, OP.



I like the look of this "hack". It adds things to PHP that I missed from C# .. now if they will add Accessors syntax, that would be nice, especially for those that use Doctrine2. PHP is as professional of a language as the user. I found fun working with PHP, C#, (node)js, python and think each has its own way, quirks and benefits.


You can easily add something like accessors using traits. I cooked this up in 5 minutes: https://gist.github.com/jsebrech/6740010

You can do a lot with meta-programming in PHP. For example, you can write your own array type if you are so inclined and use it anywhere you would use an array. Here's an experimental library that showcases the meta-programming abilities: https://github.com/jsebrech/php-o


i can do something interesting with __set and __get , but i really just want it to be part of the language. Nice ideas in the meantime tho.


PHP must be more functional and use concepts of Functional Programming but without lost current features.



obligatory X is better than php flames on the way.. php just works.. end of story


PHP just works... if you're willing to spend more time on it, find more bugs in production, have a less readable, extensible, and maintainable codebase, and have no taste.

PHP is the dream of a one-man team that gets paid by the hour. Get contract, slap something together that makes the client willing to pay, throw it all away and do it again when the client wants a change.


Just checking: do you have any experience with it? When was the last time you tried working with PHP in a team?


I've done more projects in PHP than I would care to admit. I ported the University of Chicago's "Uncommon Application" from Cold Fusion to PHP using an OO data access model, MVC, and explicit templates. (This was a long time ago before people realized that MVC was a bad idea.)

I've also hacked up a bunch of open source projects (wordpress, joomla). No tests, so you never know what you've fucked up, and you spend more time checking for regressions than actually adding that one feature you want. That's not how you do large scale software development, that's how you add pack on billable hours by charging your client for the same work 100 times.

Really, it's boils down to taste more than anything else. I've yet to see a tasteful application written in PHP.

If I were to summarize it with one anti-pattern, it's that PHP encourages people to mix unrelated parts of the program into one place, making testing, maintenance, and understanding nearly impossible. I should be able to test your app's interface without having a database. I should be able to write a database query without reading any code that touches HTML. And it's something I never see in PHP code.


> I've also hacked up a bunch of open source projects (wordpress, joomla) … > I should be able to write a database query without reading any code that touches HTML. And it's something I never see in PHP code. … > I should be able to test your app's interface without having a database.

So the answer is No, you don't have any experience with professional PHP, and you haven't used it in more than half a decade. Could have just said that.


You say MVC is a bad idea and yet you complain that php encourages mixing of things? I follow MVC and just ported a fairly large django app to php. Using smarty, I barely had to touch the Django templates. They worked almost out of the box. So if you think Django templates and structure is fine, let me tell you you can get a very similar set up using codeigniter and php.


MVP is a better idea than MVC. I'm not suggesting moving towards mixing code.


That's because you're stuck writing crap code in crap libraries.

Really, you judge PHP off of Wordpress and Joomla?


Exactly. He's comparing php to a framework. PHP isn't a framework. If he tried to write code in python or ruby without a framework or template engine, he'd have the same complaint. If he tried php with a framework or template system, he'd realize its not all that different. I just rewrote a Django app in php with very tiny modifications to the templates thanks to codeigniter and smarty.


>CodeIgniter Abandon ship immediately.


CodeIgniter is still okay. Smarty, on the other hand...


Still okay? Sure, if you like frameworks with no future at all, hacked together architecture, legacy PHP 4 code nested so deep there should be a total rewrite to remove all of it and a community which is as kindergarten as it gets.


Ever notice how everyone who complains about PHP are usually complaining about WordPress, Joomla, or other such apps?


Because these apps exist. WordPress, for example, is unparalleled in other language domains. What is the WordPress of Ruby? And in python? Is it Django? Where's the plug-in directory for Django, equivalent to [1]?

I work with WP, I'm the first to recognize it's an old codebase with all defects this entails, but popularity has value. Value that PHP critics dismiss too lightly.

[1] http://wordpress.org/plugins/


I'm not dismissing WordPress's value. Rather, I'm dismissing those that dismiss PHP out-of-hand and their lists of reasons include WordPress.


Anecdata: I just wrote a PHP application where the HTML never touched the database at all. And I'm right now working on a Java application where the database is mixed into the HTML just like the worst of the worst PHP, except because it's Java all the code is two times longer.


What is "tasteful" source code? What characteristics make a code base tasteful? Do you have any samples?


To me it boils down to the developer doing the job. Stating the obvious: you can do a great job in any language, just like you can do a crappy job in any language. I have seen tasteful applications written in PHP (hardly ever an open source application, unfortunately), what I have yet to see is a language with 100% tasteful applications.


> If I were to summarize it with one anti-pattern, it's that PHP encourages people to mix unrelated parts of the program into one place, making testing, maintenance, and understanding nearly impossible.

Haha, you are actually the problem you complain about.

Half assed "developers" who try to build anything large scale with WP or Joomla, people who can't be bothered to keep up with the changes that happened in the past 5-10 years but still complain about how shitty everything is.


  $productid = "0x4zz5";
  print $productid + 4;
If printing "8" is your idea of a working interpretation of that code, then PHP is the language for you.

If not, then PHP doesn't work. End of story.


Any programmer in almost any language who mixes types like that without understanding the implicit type conversion semantics is asking for trouble.

Implicit type conversion is evil, and I don't see how PHP's sin of favouring string -> number over number -> string is any worse than, say:

    // Javascript
    console.log(+(+!![]+(+[]+[]))); // outputs the number 10
Or:

    // C, Java

    float celsius, fahrenheit1, fahrenheit2;
    celsius = 100;

    fahrenheit1 = celsius * 9 / 5 + 32;
    fahrenheit2 = 9 / 5 * celsius + 32;

    assert(fahrenheit1 == 212); // OK
    assert(fahrenheit2 == 212); // Oops!  It's 132.  What happened?


Javascript, C and Java suck, yes. Show me something as bad as the OP in python3 and then maybe you'll have a point.


Even if Python 3's type conversion semantics has no dark corners, I still have a point.

harshreality argued that, because PHP's implicit type conversion leads to weird behaviour, "PHP doesn't work. End of story."

In that case, nearly every widely used language (with the possible exception of Python 3) "doesn't work. End of story." That's not a very interesting or useful story to tell.


Javascript, C and Java all "don't work", at least to the extent that I would never take a job writing them.


Well, you're consistent.

As I said earlier, I agree that implicit type-conversion is evil. But if I refused to use flawed tools...


I've been coding PHP for almost 8 years now. The number of times that I have come across anything even close to that example is precisely zero.


8 is sane here. The + operator adds numbers. It converts the string to a number implicitly in the process. it takes "0x4zz5" and tries to parse as much as possible. Since "z" is not a valid hexadecimal digit, it stops at z, and reads it as 0x4.

Of course, it is better to manually convert.


Well, I'd say it's never better to "try to parse as much as you can" and when encountering such an error simply silently give out a nonsense answer.

It's the computer equivalent of a bozo worker who does something random everytime they don't know how to do their job, and then tries to hide any consequences while whistling innocently.


It's not equivalent at all. It is an expected, clearly-defined behaviour - automatic, silent type conversion, with clear rules on how that type conversion works.


I'd bet 1-to-10 that if someone uses '+' operator then that line of code is never expected to encounter "0x4zz5" there. And I'm pretty sure that this addition is not meant to return a number exactly 4 less if it encounters "0z4zz5" instead of "0x4zz5". There is some theoretical chance that it does, but really, it's a lottery-type chance.

The whole total function has something that it's expected to do, some value that it returns in the end - and if it can't do that then any returned value is useless and wrong anyway; and automatic, silent type conversion is the worst possible choice of action, since it not only doesn't work, returning a value that you didn't intend (as other options); but in addition makes the actual bug hard to find and potentially corrupts a lot of stored data before you find the bug.


Things like this and some interesting developments from Facebook concerning them are mentioned in the presentation, so it would be nice if people would actually discuss that. Just a suggestion.


It's PHP. Unfortunately, enough developer got bit by the fact that PHP doesn't prevent you from shooting yourself in the foot, and shot themselves in the foot.

So, you'd probably be pretty ornery too when other people had more discipline to use the language without shooting their foot and were also employing it successfully. You'd probably want to make assumptions, and word hard to belittle them. Insult them.

And they'll talk about beauty. And zen. And wonder, and joy in a language. And they'll gloss over the major problems that it suffers from. They'll imagine all is well. And they'll try and tell you that nothing good can come from the tool they once used to shoot themselves in the foot.

Just walk away. Because you still have two feet.


PHP may have a bunch of ways to shoot yourself in the foot, but you get a new foot back right away. IMHO the oddities in PHP rarely hit you, and when they do you'll pick it up right away in PHPUnit, fix it, and walk away.


Sorry, maybe it wasn't clear, but the professional using PHP was the one walking away. =)


Yes I think I misunderstood, thanks for correcting.


Second this -- it's not only mentioned, they talk about a path to addressing this and other problems.


As a PHP developer I entirely assume that is going to print 8. I'm sure every PHP developer has had it happen or ran across it in the manual: when strings are forced into int positions PHP uses the numbers from the front of the string. Its unexpected, but consistent.


Keying it to an int via the tip of the string? Let's call it iceberg-typing.


It's PHP concatenation operator is ".".

  print $productid . 4;


You missed the point, and the problem. PHP tries way too hard to try to mangle input to kinda sorta work with the operators at hand. Were it a reasonable language, it would throw out a warning, or better yet, an error, to handle a fairly broken situation like this, rather than try to pick and choose the parts of the string it thinks is appropriate.


> a fairly broken situation

You missed the problem as well. Don't ask for trouble by creating broken situations.


Who the hell tries adding 4 to a product identifier?

I wish I could use static typing too, but when I can't I use vars that are somewhat intuitive.


How is that relevant to anything? What kind of projects do you work on where this is a problem?


Why does productid have weird number like that? Normal PI0x4zz5 instead of 0x4zz5 or just numeric figure


dont see any PHP Seriously.

Its just baby garden. Im sorry.

PHP will be Seriously if will use major Erlang features: processes, pattern matching, atoms, lists, tuples


So what you're saying is... the language that's holding about 80% of the web together isn't worth taking seriously... because it isn't Erlang? Remind me how many sites are built in Erlang again? Why would lists and tuples be critical in generating html files?


sorry for my English I just mean about these pdf - saw but not see any seriously. I mean that PHP is very seriously but I want some features of Erlang. I love PHP and programming with it but I need pattern matching and long running processes.

Tuples need because they more simple for understand and matching then lists and strings. Tuples can simple converts to lists and back. Tuples more effective with memory.

Only one class can implement tuples now its SplFixedArray. But there bugg when you call createFromArray in own custom class derived from SplFixedArray. Also with small count uts slow.

Try test Erlang and see his power. I hope you think will too, that PHP needs with Erlang features.


Alright, my mistake then.

I'll look at Erlang. I'm trying to wedge self-teaching Python into this semester.


If you need some help for any info about initial Erlang ask me.

For start:

http://www.maht0x0r.net/library/computing/erlang.pdf

http://www.erlang.org/erldoc

http://rosettacode.org/wiki/Category:Erlang

http://ruslanspivak.com/2007/09/09/erlang-for-python-program...

and you need emacs24+ for good ide and programming with erlang or just use interactive shell erl for initial start.


> mysql_escape_string vs. (sigh ) mysql_real_escape_string

ouch


I don't think bringing up deprecated functions is valid criticism. Everyone uses PDO these days.


Everyone should be using PDO these days. Whether they are is another matter. :(


I work in a large educational institution, using PHP and MS SQL Server, and I can't convince the sysadmins to install PDO because the SQL Server PDO bindings have a big red EXPERIMENTAL sign on the page (http://php.net/manual/en/ref.pdo-dblib.php). So I'm stuck using 'mssql_' functions, I'm afraid.


You can try the driver released from Microsoft http://sqlsrvphp.codeplex.com/. Haven't tried it myself though.


I'd suggest that a bigger problem with your situation is that you're trying to use MSSQL with PHP...


Good title for a joke. Idea of serious coding on templating engine can't be serious.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: