|  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: 2021-08-26 11:54 UTC
Avg. Score:4.7 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: john dot wellesz at teaser dot fr Assigned:
Status: Suspended Package: Arrays related
PHP Version: 5.5.16 OS: Debian Wheezy
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: john dot wellesz at teaser dot fr
New email:
PHP Version: OS:


 [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


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-19 06:59 UTC] fabien dot villepinte at gmail dot com
I've faced this issue recently. An array was mistakenly compared to an integer and no notice was emitted.
I'm not in favor to change the result of a such comparison but raising a notice would be a great help.
 [2021-08-26 11:54 UTC]
-Status: Open +Status: Suspended
 [2021-08-26 11:54 UTC]
I agree that it would be good if nonsentical comparisons would
somehow warn, but the details certainly need to be discussed, and
that warrants an RFC.  So anybody who is interested in this,
please pursue the RFC process[1].  For the time being, I'm
suspending this ticket.

[1] <>
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 26 23:03:37 2021 UTC