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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.