7 ms·
It's not about PHP being "uncool", it's about the many things in PHP being objectively wrong.[1] Of course it's perfectly possible to write good code in PHP, bu
by Zr40 12y ago
It's not about PHP being "uncool", it's about the many things in PHP being objectively wrong.[1] Of course it's perfectly possible to write good code in PHP, but compared to other languages, writing proper PHP requires a lot more effort.
[1] http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/ http://eev.ee/blog/2012/04/09/php-a-fractal-of-bad-design/
- ThomPete 12y agoNothing is objectively wrong in computer languages or any other languages. If it had been objectively wrong then the language wouldn't have been useful at all. The purpose of a programming language is not to allow you to write beautiful code but to produce things. Everything else is a pseudo debate that is necessary at times but not as much as some would like.
- xrstf 12y agoPlease stop sharing this blog post like it's the Holy Grail. It's full of nonsense and false information about PHP. Not that there aren't issues in PHP, but this assembly is just "PHP doesn't have feature X and doesn't behave like language Y, so it must be bad. I didn't bother reading the documentation or any code written after 1998.".
- Mithaldu 12y agoIs ?: still left associative in PHP?
- imakesnowflakes 12y agoOh, documentation. It is still broken, even on the most basic level, I should say. http://www.reddit.com/r/lolphp/comments/2md8c0/new_safe_casting_function_rfc_casting_10_to/cm3djvj http://www.reddit.com/r/lolphp/comments/2md8c0/new_safe_cast...
- joepie91_ 12y ago> nonsense and false information Such as?
- xrstf 12y ago- being able to declare a class abstract is a bad thing, apparently. - "(int)" being a single token in the language - not being able to call "array()" as a function is bad, apparently (which is the equivalent of wanting to use "return" as a function in C) - "Most error handling is in the form of printing a line to a server log nobody reads and carrying on." - Bullshit. We send errors to Sentry or via e-mail. In some projects we feed them to a database. - "E_STRICT is a thing, but it doesn’t seem to actually prevent much and there’s no documentation on what it actually does." - Bullshit. It's a warning, not a magic fix, so what should it do except warn you? - "Function arguments can have “type hints”, which are basically just static typing. But you can’t require that an argument be an int or string or object or other “core” type, even though every builtin function uses this kind of typing, probably because int is not a thing in PHP." - Yeah, read the RFCs concerning type hints to understand the issues why PHP does not have them [yet]. - "No named arguments to functions. Actually explicitly rejected by the devs because it “makes for messier code”." - "And so I list it as a fundamental flaw in the language because it's not Python." - "new, private, public, protected, static, etc. Trying to win over Java developers?" - Oh sorry, PHP devs will stop adopting good coding pratices in the next releases. Back to var everyone! - "Subclasses cannot override private methods." - Yeah, that's why they are called PRIVATE. - "There are no constructors or destructors. __construct is an initializer, like Python’s __init__. There is no method you can call on a class to allocate memory and create an object." - Yeah, because IT'S FRICKIN' PHP and you should not fiddle with memory. Go write C if you want to deal with malloc. - "Static variables inside instance methods are global; they share the same value across all instances of the class." - Yeah, that's why they are static. If you want instance-bound variables, use class members. - "As namespaces are a recent feature, the standard library isn’t broken up at all. There are thousands of functions in the global namespace." - "How dare the PHP devs not break compat with every piece of code ever written when they introduced namespaces? They should have just converted everything to C#!" - "How do you sort backwards? In PHP, there’s a separate function called rsort()." - Fuck, those PHP dev assholes. How dare they include a shortcut. It's almost as if they just wanted to make simple things simple. PHP should require the developer to implement 20 interfaces to compare two numbers! - "preg_replace with the /e (eval) flag will do a string replace of the matches into the replacement string, then eval it." - Failure to mention that this behaviour is deprecated for ages now (dunno, has it been removed in 5.6?) - mentioning classkit as a way to "actually be dynamic in PHP". Yeah sure, without classkit there is NO dynamic feature in PHP, none at all. - "There is no exponentiation operator, only the pow function." - Wrong, there is now. - "No Unicode support. Only ASCII will work reliably, really. There’s the mbstring extension, mentioned above, but it kinda blows." - Yeah, no website with Unicode support has ever been built with PHP. Sure. Don't ask me how I manage to handle Unicode with mbstring just fine, I must be a magician. - "Similarly baffling, arrays stringify to Array with an E_NOTICE." - What else would you like? A JSON representation? A simple comma seperated list? I can guarantee you, whatever you choose, someone will find it bad for their purpose. That's why we consider plainly converting an array to a string a MISTAKE (aka bug). - "var_dump(strstr) issues a warning and assumes you mean the literal string, "strstr"" - aka "PHP is not JavaScript, so it's bad." - "There are no generators. (Fixed in 5.5. Wow. They basically cloned the entire Python generator API.)" - Dafuq do you want? For some things, Python is the best thing in the world and everyone should copy it, but when PHP does, it's also bad, because, ya know, PHP. - "PHP is naturally tied to Apache. Running it separately, or with any other webserver, requires just as much mucking around (possibly more) as deploying any other language." - Welcome to 2014, dickhead. I never heard our admins complain about using PHP-FPM with nginx. And using PHP separately couldn't be simpler: ``php myscript.php``. - "Similarly, there is no easy way to “insulate” a PHP application and its dependencies from the rest of a system." - This guy has seen too many PEAR-based projects. - "Configuration files and other “partials” need C-like guards to prevent them from being loaded directly." - a) put the file somewhere outside the docroot; b) configure your webserver to not spew out static files; c) use plain PHP files for config files; d) deny access to config files via .htaccess - "No XSS filter. No, “remember to use htmlspecialchars” is not an XSS filter." - I beg to differ. - "No CSRF protection. You get to do it yourself." - Fuck, you have to implement application logic yourself. Damn. - "No authentication or authorization." - sigh really? - "No routing. Your website looks exactly like your filesystem. Many developers have been tricked into thinking mod_rewrite (and .htaccess in general) is an acceptable substitute." - And in fact, it is. - No coherent deployment mechanism; only “copy all these files to the server” -- Yeah, this is truly the worst. Just uploading files is waaaaay not enterprisy enough. Without OpsWorks, Chef and fourteen admins, you can't even call a PHP deployment a "real deployment". Things should be complicated. When uploading new code, PHP should force you to pester the admin to restart Apache! - "The original built-in MySQL bindings, still widely-used, have no way to create prepared statements." - Yeah, because that wasn't a thing back when ext-mysql was written. That's why we moved to mysqli/PDO YEARS ago. ----- But hey, it's logical to not remove fixed issues from the list. The point of the list is not to detail the actual flaws, but to just shit on PHP. It's like me shitting on the first alpha of Python or how much Linux 0.0.1 sucked. Also, you will note that I left out quite a few points that the author brought up. And that's because they are valid points of criticism about PHP. I'm not denying that. But if you shit on PHP, get your shit together first and don't assume all PHP is like a guestbook script from 2003.