php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43545 Object cast to int failure, multiple versions
Submitted: 2007-12-09 14:49 UTC Modified: 2008-01-29 00:46 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mark at dynom dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2007-12-09 14:49 UTC] mark at dynom dot nl
Description:
------------
When comparing objects with integer types the notice:

"PHP Notice:  Object of class Foo could not be converted to int in Command line code on line 1"

is raised, this only happens when not using strict checks (== vs ===)
It has been tested on multiple builds 5.1.6, 5.2.2, 5.2.4 and 5.2.5.

Reproduce code:
---------------
FAILS
php -r 'error_reporting( E_ALL ); class Foo { } $foo = new Foo; var_dump( in_array($foo, array(0)) );'

WORKS
php -r 'error_reporting( E_ALL ); class Foo { } $foo = new Foo; var_dump( in_array($foo, array("foo")) );'


// More examples: http://pasteosaurus.com/44812

Expected result:
----------------
I exepected to get: bool(false)

Actual result:
--------------
$ php -r 'error_reporting( E_ALL ); class Foo { } $foo = new Foo; if ($foo == 1) {}';

Notice: Object of class Foo could not be converted to int in Command line code on line 1

Call Stack:
    0.0001      68456   1. {main}() Command line code:0


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-29 00:46 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 16 20:01:32 2025 UTC