Re:What's new in PHP 8?
by darthrupert on Friday August 14, 2020 @01:30AM
(#24154034)
These are easy questions.
1. If you convert a string which has non-numbers to an integer, an error is raised
2. Truthiness should not exist as a concept. Just booleans and expressions that evaluate to booleans.
PHP's backwards compatibilty promise makes these more difficult questions, of course.
Re:What's new in PHP 8?
by Erlich_Bachman on Sunday August 16, 2020 @03:30PM
(#24180497)
> 2. Truthiness should not exist as a concept.
Meh, it's actually quite useful in many situations.
Easy questions but not obvious answers.
What kind of error to raise? Do you return a NaN? Throw an exception? Both have their uses.
Re:What's new in PHP 8?
by darthrupert on Friday August 14, 2020 @04:51AM
(#24155494)
Throw a standard exception. E.g. python calls it a ValueError. Returing NaN is clearly wrong design.
The types form a hierarchy in my mind, from simple to complex: from boolean to integer, to float, to string, to compound types like arrays and objects. It seems like values should cast up and down the chain uniformly.