4 ms·
A quick dive into any PHP-related topic on HN should yield significant answers. Part of the hatred comes from the fact that the way people know PHP is from 2005
by MAGZine 13y ago
A quick dive into any PHP-related topic on HN should yield significant answers. Part of the hatred comes from the fact that the way people know PHP is from 2005, when it was essentially one really long procedural program. It's not so much that people ignore the recent upgrade in tooling/modern language constructs so much as people aren't familiar that they exist.
However, these is still a lot of vitrol for PHP. Because it is so easy to use, many people are able to pick it up without any prior SE experience--these people tend to create poorly-designed, slow-running, and, perhaps worst of all, dangerous (vis a vis security) code.
The other major complaint that exists has to do with inconsistency/insanity in PHP's function signatures/naming/evolution. For example: mysql_escape_string and it's sister, mysql_real_escape_string. Although, anyone working with modern PHP probably will never touch these functions.
What is overlooked is that it has an extensive base of developers, it DOES scale (this is proven), and the language is improving (as well as the tooling (PHPUnit, XHProf, CI tools), frameworks, package management etc). And although Facebook does use it, it's important to note that, AFAIK, PHP only exists as a thin layer in between "display HTML" and "communicating with backend servers which are going to handle the majority of the work, save for presentation-layer type stuff."
There are a few alternatives to PHP, but they each have their warts too. Ruby is hilarious slow, for example.
- drjake 13y agoThanks so much for your time! I was wondering whether you would suggest using PDO or mysqli for connecting to mysql via PHP?
- LDN 13y agoFrom my personal experience I would suggest working with PDO. It is easy to implement, supports multiple drivers if needed and has named parameters in your prepared statements. The difference in terms of performance should be insignificant - although I think in some cases mysqli tends to execute faster.
- cafard 13y agoIt also has the merit for Perl developers of being more or less like Perl's DBI.
- nthj 13y ago> Ruby is hilarious slow, for example. [citation needed]. Also, relevant Stack Overflow debate is available. [1] TL;DR: yes, of course Ruby is slower than, say, C, but today's bottleneck isn't hardware, it's developer productivity. (Developer time costs way more than hardware.) [1] https://stackoverflow.com/questions/2529852/why-do-people-say-that-ruby-is-slow https://stackoverflow.com/questions/2529852/why-do-people-sa...
- skywhopper 13y agoDepends on the task. Most of my programming is on the sysadmin side. So automation and log processing are two of the biggest things I deal with. I love Ruby to death. I'd program in it all the time if I could. And it works really well for automation. But for processing massive amounts of data? Not so much. I even did some tests a year or so ago when I was writing a script to merge together data from multiple log files and a couple of databases, including data transformations, merging/collation and sorting of, oh 100GB or so of raw log data a day. My first tests with Ruby were running pretty slow, so I decided to write the script out as I'd planned in both Ruby and Perl and compare the results on subsets of the data. I used none of Ruby's OO features, I just did straight simple data structures, hashes and arrays, etc. Ruby has far better infrastructure for dealing with these things built in, and so I wrote the Ruby script in a couple of hours. The Perl script took me a couple of days--admittedly my Perl is rusty, but I wasn't doing anything complicated. But the language just doesn't have as much stuff built in. Anyway, at the end I had two scripts with exactly the same logic, and I'd even had to implement some things (like Ruby's Array#uniq, which I assume (but don't know) is written in C) from scratch in Perl. So yeah I wasted 16 hours on the Perl script, but you could follow them line by line and they were identical. Run them one after the other to compare, and the Perl script is literally 100 times faster and uses a tenth of the RAM. I told my Python-loving friends about this and they guffawed at the silly Ruby guy, but it was depressing. So yeah, Ruby is slow at runtime compared to other languages. Usually that doesn't matter, but sometimes it matters a lot.
- eCa 13y agoAs an aside, Perl's uniq is in List::MoreUtils [1]. [1] https://metacpan.org/pod/List::MoreUtils https://metacpan.org/pod/List::MoreUtils
- mef 13y agoCare to point folks to an example of a more modern PHP script that shows off improvements since the state of things in 2005?
- krapp 13y agohttp://laravel.com/ http://laravel.com/
- jwblackwell 13y agoLaravel is a great framework and has really helped push the community towards writing tests and producing packages that can be easily shared via composer. Of course Symfony has a big part to play in Laravel's success to. 2013 was a good year for PHP. Most of the time when I hear people complaining about the language, it's as if things haven't changed since 2005. There's a lot of horrible, badly written spaghetti code out there in PHP that doesn't exist in other languages, but there's also probably much more decent code written in PHP and I think that trend is only set to continue.
- krapp 13y agoThe only thing I think I don't like about Laravel is that it doesn't use Twig as the default template engine.
- lukeholder 13y agoFully agree. Check out twig bridge though.
- krapp 13y agoAlready using it. Autoescape and a function whitelist are beautiful things...
- Volscio 13y agoI'm surprised people aren't quicker to mention the fact that PHP was (and still is!) responsible for many simple SQL injection database dumps/hacks. A simple string termination was all it took. That I felt gave PHP a massively bad rap as they spent versions after that trying to figure out a way to prevent/deter it. Nowadays with wrappers it's thankfully less of a problem. Having just come off a Drupal project myself but having looked at the latest PHP additions as well as Laravel though, it seems to me that many languages are converging and borrowing from each other, which I love. Latest PHP is pretty sweet.
- mcintyre1994 13y agoAnd anybody who learnt of their own accord probably had Google rapidly lead them to w3schools, and if they were really unlucky they might have noticed they have PHP tutorials. Their database query code used to use mysql_query with absolutely no protection, the basic sql injection disaster scenario. It now uses non-prepared mysqli_query, which a quick Google tells me still isn't safe. I'm sure everyone here knows it, but w3schools is seriously dangerous and seems like it will indefinitely damage the image of PHP.
- krapp 13y agoThis really has been one of the cancers at the heart of PHP development. Most of the reasons people give for hating the language amount to semantic issues which make it different than the language they'd prefer it to be, or syntax which, while annoying, can be dealt with, or edge cases no one is ever likely to encounter in actual practice (although I just recently saw an example of someone's PHP where they were including php files using shell_exec so the rabbithole of 'actual practice' can get pretty deep.) The way SQL is implemented and executed still primarily is one of the primary arguments against, at the very least, not learning PHP properly. And it's definitely a point in the column of any framework in any language which can say that SQL injection and remote code execution are impossible in frameworks written in that language.
- dk01 13y agoBasically PHP is the America of programming languages.