|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33999 object remains object when cast to int
Submitted: 2005-08-04 23:49 UTC Modified: 2005-08-05 11:02 UTC
From: crywolf at kyndimarion dot net Assigned: dmitry (profile)
Status: Closed Package: Class/Object related
PHP Version: 5CVS-2005-08-05 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
21 + 46 = ?
Subscribe to this entry?

 [2005-08-04 23:49 UTC] crywolf at kyndimarion dot net
When attempting to cast an object to an int, it remains untouched.  No warnings or errors are displayed.  The results are the same for (int), intval(), and settype().  float, bool, string, and array all seem to work correctly.  I get the same results in both 5.0.3 and 5.1.0b3.  In 4.3.11, an object can be cast to int.

Reproduce code:

class Foo {
var $bar = "bat";

$foo = new Foo;

$bar = (int)$foo;

$baz = (float)$foo;


Expected result:
object(Foo)#1 (1) {
  string(3) "bat"

Actual result:
object(Foo)#1 (1) {
  string(3) "bat"
object(Foo)#1 (1) {
  string(3) "bat"

Notice: Object of class Foo could not be converted to double in /home/crywolf/Test/cast_object.php on line 14


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-05 00:04 UTC]
Dmitry, I guess we need to return at least objects index in  this case.
Or maybe use the same way we use when compatibility_mode is on.
What do you think?
 [2005-08-05 11:02 UTC]
Fixed in CVS HEAD.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 12:01:28 2024 UTC