News for hackers. Stuff that matters.
Re:What's new in PHP 8? by combatentropy on Friday August 14, 2020 @01:18AM (#24153907)
Should a string, when converted to an integer, become 1, not 0? (Unless it is a string of only digits, like "567". Then it should become 567.)

  (bool) 'x'  //  true
  (int) true  //  1
If a string is truthy in a boolean situation, shouldn't it also be truthy in a numeric one?

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.

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.

Re:What's new in PHP 8? by pavlov on Friday August 14, 2020 @04:07AM (#24155178)
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.