Bug #81398 [Opn]: Comparing int/string with max() always returns string

From: Date: Sun, 29 Aug 2021 22:38:24 +0000
Subject: Bug #81398 [Opn]: Comparing int/string with max() always returns string
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236163@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81398&edit=1 ID: 81398 Updated by: danack@php.net Reported by: php at ober-mail dot de Summary: Comparing int/string with max() always returns string Status: Open Type: Bug Package: *Math Functions Operating System: Debian 10 PHP Version: 8.0.10 Block user comment: N Private report: N New Comment: The next sentence is: "The actual value returned will be of the original type with no conversion applied." Which seems quite clear to me. Previous Comments: ------------------------------------------------------------------------ [2021-08-29 21:58:00] php at ober-mail dot de I'm sorry, of course the "Test script" should be: <?php var_dump(max("A", 1)); var_dump(max(1, "A")); ------------------------------------------------------------------------ [2021-08-29 21:57:10] php at ober-mail dot de Description: ------------ The documentation of max() says: "Values of different types will be compared using the standard comparison rules. For instance, a non-numeric string will be compared to an int as though it were 0." Using PHP 8.0 and above, I'm observing a deviating behavior, that is, the string value is returned instead. Parameter order does not matter. If this is the intended behavior, the documentation should be updated / the cited snippet should be removed. Up to PHP 7.4.13, the observed result matches the documentation. Test script: --------------- <?php var_dump(max("A", PHP_INT_MAX)); var_dump(max(PHP_INT_MAX, "A")); Expected result: ---------------- int(1) int(1) Actual result: -------------- string(1) "A" string(1) "A" ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81398&edit=1

« previous php.bugs (#236163) next »