PHP sucks. Face it, it does. How can it be 2006, and PHP 5.1.0 still doesn't have namespaces? Or scoping?
PHP is developed and maintained by people with a âhands offâ approach and clearly no idea of where the language is going, let alone where it should be going.
The main points that stick out for me:
- Most of the world has moved away from embedding code in content (HTML). Get yourself a good template library and clean up your code. What's more, different people can work on different areas (code or content) depending on their expertise. Very important for large teams.
- No namespaces. Better prefix all your function names with something unique, otherwise the names might clash with those from other scripts.
- Back-assward scoping. Ok, so variables aren't declared, simply appearing when first needed. Those used outside of functions are essentially global. But functions do get their own scope. So if you want to use one of the global variables in your function, you have to declare so with globalÂ $somevar;.
- Quotes. My god, can we use prepared statements (like the Perl DBI) and do away with this stupid attempt at a language-wide workaround for an SQL-injection vulnerability? I still see DB-driven PHP pages with single quotes appearing as \'.
- So many functions! PHP replicates most of the Perl functions, then adds more from lib C, then adds even more! Core functionality for file I/O, string manipulation, etc is implemented at least two or three times!
- Ugly URLâs. PHP is firmly a file-centric interpreter. I hate seeing long URLâs with a dozen arguments, especially sites all driven out of index.php.
But perhaps the biggest reason PHP sucks is that people use it to make large web sites. Do you know what PHP originally stood for? Personal Home Page. It was a simple Perl CGI script to add dynamic elements to simple web pages. And for that it is probably still the best language to learn. But because of its simplicity, people learnt it and it became popular. And because it became popular, the developers extended it with DB functions and the like. And now people have constructed very large and complex web sites using a language that was never meant for large-scale development. That's the biggest problem with PHP. Learn it if you want. Go ahead and use it in your simple home page. But for gods sake, move onto another language and framework if and when you want to make anything bigger.
- Experiences of Using PHP in Large Websites
- Why PHP sucks (for large systems)
- Some more links at PHPSucks
- Tim Bray on PHP
- Keith Devens hates PHP
- Stefan Esser resigns from the PHP security group - "I stopped counting the times I was called immoral traitor for disclosing security holes in PHP"
In comparison to Perl
- PHP in contrast to Perl
- ReÂ²: Is Perl a good career move?
- perl.advocacy: My list of PHP's shortcomings
- "Iâm sorry, but PHP sucks" by Jonas Maurus goes into detail about a number of issues
- Slashdot comment: âUghâ is what I say when I think of PHP
- The announcement of PHP 5.1.0 on slashdot has a large number of negative comments. Could it be that people are waking up to PHP's inadequacies and turning against it? I can only hope.
- A recent story on slashdot claiming "SQL Injection Attacks Increasingâ. Many posters attacked the claim that âSQL injection is a real pain for web developers", pointing out that it's pretty much PHP programs/programmers that have such a problem with SQL injection attacks:
other languages simply support prepared statements, which sidesteps the entire problem. No escaping necessary, just use a parameterized SQL statement. They also support the standard string concatenation method, but prepared statements are there from the start, and many examples make use of this. Although there is a package for PHP to support parameterized SQL, all the PHP I've seen simply uses string concatenation.
- In an Ask Slashdot about looking for Java-based CMS's and the difficulty of finding a Java host, some clown claimed that Java offers no advantages over PHP. I joined in with two comments that got modded up fairly well.