doc-en icon indicating copy to clipboard operation
doc-en copied to clipboard

max example error

Open mowangjuanzi opened this issue 3 years ago • 4 comments

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

mowangjuanzi avatar Oct 15 '22 17:10 mowangjuanzi

Ah, right, that behavior changed as of PHP 8.0.0, so the documentation needs to be updated. Thanks for reporting!

cmb69 avatar Oct 15 '22 18:10 cmb69

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.

talkinnl avatar Oct 16 '22 07:10 talkinnl

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.

mowangjuanzi avatar Oct 16 '22 07:10 mowangjuanzi

Is the same for the min() function

mowangjuanzi avatar Oct 16 '22 11:10 mowangjuanzi

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.

afilina avatar Jul 17 '23 17:07 afilina

Vaguely related is #2016

Girgias avatar Jul 25 '23 16:07 Girgias