|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #67904 Array/object to number/string comparison should be deprecated
Submitted: 2014-08-26 02:48 UTC Modified: -
Avg. Score:4.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: john dot wellesz at teaser dot fr Assigned:
Status: Open Package: Arrays related
PHP Version: 5.5.16 OS: Debian Wheezy
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2014-08-26 02:48 UTC] john dot wellesz at teaser dot fr
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

I think that this 'feature' is detrimental to PHP and a source of confusion and waiting to happen catastrophes.

- 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:

error_reporting(E_ALL | E_STRICT);

var_dump([7, 11] > 'foo', [1] > 42);

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request

PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon Jun 24 23:01:25 2019 UTC