9 ms·
While documented, that is surprising behavior. If it takes in an int, shouldn't it be able to take in PHP_INT_MAX? And shouldn't it yell at you instead of just
by _asummers 11y ago
While documented, that is surprising behavior. If it takes in an int, shouldn't it be able to take in PHP_INT_MAX? And shouldn't it yell at you instead of just silently going about its day?
- sneak 11y agoAlmost everything in PHP is surprising behavior. And yes, in the eleventy billion cases where PHP should yell at you that it's doing something totally different than what you wanted, it instead just goes about its day silently.
- KingMob 11y agoWhich is why it was a great fit for MySQL, which would silently store invalid dates and truncate over-long strings with no warnings.
- vog 11y agoThis is so true. It is the main reason I switched to PostgreSQL and never looked back.
- gmac 11y ago... and accept nonsensical SQL queries, returning whatever it feels like.
- mratzloff 11y agoYou joke, but I'm pretty sure this is one of the reasons why that stack was so successful. Same principle behind HTML rendering. "It's displaying something, isn't it? Errors are only suggestions."
- krick 11y agoI'm not so sure. It's kind of true for HTML (forgiveness was not "good" property of the format, but of the browser: 1 site works in one browser, but not in the other, and user will blame the browser, so let's display whatever the hell we can). But PHP in the early days was kinda handy (even though hacky) tool, allowing to use simple syntax to render HTML instead of custom Perl-scripts. And then it just got popular. MySQL was once actually superior open-source database, being more performant and simpler to setup and use than PostgreSQL. And then, once again, it just got popular. I don't think being faulty helped these technologies, although it sometimes is the case.
- k_roy 11y agoThere are warnings. Most people just ignore them in their APIs
- KingMob 11y agoTrying to insert over-large data should have been an error by default from the outset, never a warning. Ilooked at MySQL in 2000 and went "You had one job, database; protect my data."
- sarciszewski 11y agoEven worse, some of the Internals teams argue in favor of silently trucking along instead of, e.g. throwing an exception: http://www.serverphorums.com/read.php?7,1250372 http://www.serverphorums.com/read.php?7,1250372 EDIT: because of HN's annoying "you are posting too fast" limit I cannot reply to the comment below. The arguments against Exceptions began in the comments on the relevant pull request: https://github.com/php/php-src/pull/1397 https://github.com/php/php-src/pull/1397
- juliangregorian 11y agoWow, that thread is current! This mentality really is systemic to PHP. It's like the exact opposite of "let it crash".
- claar 11y agoActually that thread seems to strongly argue that either an Exception or fatal error should be thrown. I'm not seeing anyone in that thread wanting to silently truck along -- am I missing it?
- _lce0 11y agofrom that thread.. At what point do we stop blaming the developers for not knowing how to use our badly designed features, and accept responsibility for exposing an API that is hostile towards simple, efficient, and correct implementations?
- paragon_init 11y agoIt might be worth noting that 'sarciszewski was the author of that remark.
- coldtea 11y ago>Almost everything in PHP is surprising behavior. It's not. White it does have several surprising behaviors, "almost everything" is just an example of uniformed BS people say when it comes to PHP. C also has undefined behavior and several bad decisions, ditto for C++, Javascript, etc. But PHP is just an easy target for trolls.
- mikeash 11y agoThe PHP approach seems to be that any crazy behavior is acceptable as long as it's documented.
- dspillett 11y agoTo be fair, that is not an uncommon situation elsewhere either.
- mikeash 11y agoI think it is. Sure, there are plenty of calls out there in all sorts of systems that have crazy, documented behavior. But it's rare to see anyone outside of the PHP world defending the crazy behavior purely on the basis that it's documented. Crazy behavior is almost always there because of compatibility concerns, performance concerns, or an acknowledged bug that just hasn't been fixed yet. Outside of PHP, I rarely see anyone just say, "It's fine, that's how it's documented to behave" and leave it at that.
- BuildTheRobots 11y agoOutside of php and systemd..... <Friday afternoon trolling is just too easy this week />
- dspillett 11y agoAnd mySQL of old. I assume things are much better now, but I remember a time when things like INSERT <table> (<date_field>) VALUES ('2015-02-30') would not have raised any sort of error, amongst other terrible things that people would defend having to implement explicit checks for in other layers of your application.
- slapresta 11y ago> I assume things are much better now Nope: http://grimoire.ca/mysql/choose-something-else http://grimoire.ca/mysql/choose-something-else
- deleted 11y ago[deleted]
- Navarr 11y agophp > echo PHP_INT_MAX; 9223372036854775807
- k8tte 11y agothe error is from php 4.2 or something.
- saucetenuto 11y agoAh, I see, I just misunderstood their interface. Thanks.
- deleted 11y ago[deleted]
- jwatte 11y agoThat is not the PHP way.