note 65484 added to function.max

From: Date: Mon, 01 May 2006 23:26:58 +0000
Subject: note 65484 added to function.max
Groups: php.notes 
Request: Send a blank email to php-notes+get-110314@lists.php.net to get a copy of this message
During a discussion on IRC we noticed what we thought was an odd behaviour. After looking over the various different tests we produced, we came to the conclusion that the following statement applies to min() and max(): "All arguments are cast to the type of the first value for comparison, but are returned as the type they were passed in as." This becomes most noticed when comparing boolean types to integers. max(true,100) will return differently than max(100,true). Another behaviour that was also observed is that min() and max() will return the first item, in its native type, when multiple values satisfy the condition. This can produce unexpected behaviour if not handled properly. For example, min(false,0) will return (bool)false, where min(0,false) will return (int)0. Hope this takes care of some of the confusion. ---- Server IP: 216.194.113.175 Probable Submitter: 198.248.45.10 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.max.php Edit -- http://master.php.net/note/edit/65484 Del: integrated -- http://master.php.net/note/delete/65484/integrated Del: useless -- http://master.php.net/note/delete/65484/useless Del: bad code -- http://master.php.net/note/delete/65484/bad+code Del: spam -- http://master.php.net/note/delete/65484/spam Del: non-english -- http://master.php.net/note/delete/65484/non-english Del: in docs -- http://master.php.net/note/delete/65484/in+docs Del: other reasons-- http://master.php.net/note/delete/65484 Reject -- http://master.php.net/note/reject/65484 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#110314) next »