3 ms·
"Else you are not getting the authentic php4 experience!" /s PHP has been in a poor shape for many, many years. It started shaping up in last rather few years,
by nine_k 5y ago
"Else you are not getting the authentic php4 experience!" /s
PHP has been in a poor shape for many, many years. It started shaping up in last rather few years, and there is a large backlog to tackle, colossal if you include all the numerous tutorials and Q&As from getting copy-pasted since 2000.
- mschuster91 5y agoThe language never was the problem, not since PHP 5.1 at least (which introduced PDO) and that is 16 years ago. The problem always was the ecosystem that took decades to update and the fact that Google's search is algorithm-ranked and not supposed to be curated by humans, which would have kicked out at least the most horribly insecure stuff.
- jeltz 5y agoI disagree. As someone who has used PDO a lot it still makes it unnecessarily hard to use parametrized queries compared to the libraries available in most other languages, even C (at least for PostgreSQL). The pgsql library for PHP is also pretty good, better than PDO.
- habibur 5y agoBut, you need to write the hard thing once. In a 10 line wrapper function and then call that function from everywhere. sql_query($db,$sql,$params); Problem solved. I guess every PHP developer writes a bunch of these wrapper functions for common sql tasks before he starts his work.
- porker 5y agoOr installs Doctrine DBAL which handles it all for you. At the cost of some performance, but the ease-of-use with a highly-tested and relied-upon library normally outweighs that.
- Cthulhu_ 5y agoYup, make it work (securely!) before making it fast; you can't diagnose performance if your code isn't working as it should in the first place (and SQL injection safety is a non-functional requirement; you can't consider code working if there's that weakness). In practice, bad database design or access (like the n+1 problem) will weigh heavier than the overhead added by a library like Doctrine. Or, it should, if Doctrine adds THAT much overhead it's a problem.
- arp242 5y agoThis is the most PHP comment in this thread yet; "yeah, I know this very basic API is inadequate and broken, but you can just write a wrapper, everyone is writing the same wrappers anyway!" Is PHP supposed to be a high-level language or what? Hell, I'd consider it a very flimsy excuse even in C (in most contexts anyway).
- tored 5y agoAlready answered in this thread. There is nothing hard or wrong about the API. It is just lots of misunderstandings and commentators not looking things up before commenting. $stmt = $pdo->prepare('INSERT INTO user (email) VALUES(?)'); $stmt->execute([$email]); https://news.ycombinator.com/item?id=27954454 https://news.ycombinator.com/item?id=27954454
- tored 5y agoYou can do parametrized queries in two lines of code with PDO. I wouldn't classify that as "unnecessarily hard", sure you could split in half to one line of code, for that you need to write your own wrapper function.
- toast0 5y agoI mean, PDO wasn't great (in contrast to perl's DBI which was pretty good and offered parameterized queries even if the underlying interface didn't), so it made sense to prefer mysql_query. But mysql_query didn't do parameters, and mysqli did, but only it you ran a new enough version of MySQL. I wouldn't call it a language failure per se, but a problem with the libraries that shipped with the language. That distinction may not make a difference. Bad examples that stuck around don't help either, of course.
- kadoban 5y agoLong after PDO was a thing, the official docs still included the old insecure jank. Is your contention that Google is to blame for indexing them?
- acdha 5y agoPDO was slower, the interface - critically - tons of examples still either made prepared statements a side note or actively encouraged string concatenation, and it preserved the flaws of the previous interfaces like ignoring errors and warnings (silent is no longer the default in PHP 8). I no longer consider myself part of the PHP community (started around 1999), in part due to the low priority reliability and security had. It was exhausting having to vet code so frequently because even experienced developers forgot all of the rakes in the grass.