doc-en
doc-en copied to clipboard
max example error
https://github.com/php/doc-en/blob/master/reference/math/functions/max.xml#L100
// The string 'hello' when compared to an int is treated as 0
// Since the two values are equal, the order they are provided determines the result
echo max(0, 'hello'); // 0
echo max('hello', 0); // hello
actual output:
hello
hello
Ah, right, that behavior changed as of PHP 8.0.0, so the documentation needs to be updated. Thanks for reporting!
It feels like a unrealistic, mixed type use case from the past. I think the proper fix is to remove this example completely, less is more.
Not only these. other similar descriptions. I feel like I have to delete it.
<function>max</function> returns the parameter value considered "highest" according to standard
comparisons. If multiple values of different types evaluate as equal (e.g. <literal>0</literal>
and <literal>'abc'</literal>) the first provided to the function will be returned.
and so on.
Is the same for the min() function
I think that the example needs to be removed, since it's incorrect. The behavior change should be recorded in the changelog. It probably has to do with the new way PHP compares numbers to strings. It's a similar change that pops up in dozens of functions, although I'd like to address min and max for now.
Vaguely related is #2016