Req #67904 [NEW]: Array/object to number/string comparison should be deprecated

From: Date: Tue, 26 Aug 2014 02:48:44 +0000
Subject: Req #67904 [NEW]: Array/object to number/string comparison should be deprecated
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187273@lists.php.net to get a copy of this message
From: john dot wellesz at teaser dot fr Operating system: Debian Wheezy PHP version: 5.5.16 Package: Arrays related Bug Type: Feature/Change Request Bug description:Array/object to number/string comparison should be deprecated Description: ------------ Currently when a an array/object is compared to a number (or string), PHP doesn't issue any E_NOTICE or E_STRICT, the comparison is done and the array/object is always greater (as documented in http://php.net/manual/en/language.operators.comparison.php). I think that this 'feature' is detrimental to PHP and a source of confusion and waiting to happen catastrophes. Reasons: - 99.9% of such comparison are programming mistakes. - There is no reason to expect objects or arrays to be always greater than _any_ number or string. - The fact that no error at all is thrown when such comparison is performed is generally unexpected. So I think that in future versions of PHP it would be nice if at least an E_STRICT was thrown. Test script: --------------- <?php error_reporting(E_ALL | E_STRICT); var_dump([7, 11] > 'foo', [1] > 42); Expected result: ---------------- E_STRICT NULL E_STRICT NULL Actual result: -------------- bool(true) bool(true) -- Edit bug report at https://bugs.php.net/bug.php?id=67904&edit=1 --

« previous php.bugs (#187273) next »