Their PHP8.5 examples are written as:
var_dump(max($value, min($lower_bound, $upper_bound)));
but that should be: var_dump(max($lower_bound, min($value, $upper_bound)));
/facepalm max($value, min($lower_bound, $upper_bound)) when $value < $lower_bound: $lower_bound
max($value, min($lower_bound, $upper_bound)) when $value > $upper_bound: $value
max($value, min($lower_bound, $upper_bound)) when $value is between them: $value
max($lower_bound, min($value, $upper_bound)) when $value < $lower_bound: $lower_bound
max($lower_bound, min($value, $upper_bound)) when $value > $upper_bound: $upper_bound
max($lower_bound, min($value, $upper_bound)) when $value is between them: $value
If the former was what's actually written then yeah, it would be incorrect. However, if you swapped arguments 1 and 2 for each clamp() call, they'd give the same result, and for what you say the PHP 8.5 example is written as, there's no call given where $value > $upper_bound.I don't know if this makes much sense, though that's all the more reason for needing clamp().
That is false. The bounds are [0, 100] in both examples and 0 is correctly put as the first parameter to max() in 8.5.
$value = max($value, $lower_bound);
$value = min($value, $upper_bound);
var_dump($value);
10 years from now I can thoughtlessly scan over that without having to think what is going on.This is great:
clamp($value, $lower_bound, $upper_bound);
It's even more readable.And since I cant stop typing... (sorry lol)
$trucks = trucks($ordernum);
$boxes = $boxes_per_truck * $trucks;
$bananas = $bananas_per_box*$boxes;
$bananas = max($bananas, $lower_bound);
$bananas = min($bananas, $upper_bound);
var_dump($bananas);
In stead of: var_dump( max($lower_bound,min($boxes*$bananas_per_box*trucks($ordernum)*$boxes_per_truck,$upper_bound)));I get the popularity and installed-base arguments, but I shudder when I see the code.
New CVEs/RCEs? https://www.php.net/archive/2026.php#2026-11-18-1
Perl was famous for excellent native unicode support in its native string type, but the result was that you had to keep track of whether your variable was native unicode or octets, and many CPAN modules would try to transparently support both, in buggy ways. A richer system is not always an advantage.
- no RCE