#33999 [Asn->Csd]: object remains object when cast to int

From: Date: Fri, 05 Aug 2005 09:02:52 +0000
Subject: #33999 [Asn->Csd]: object remains object when cast to int
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-83006@lists.php.net to get a copy of this message
 ID:               33999
 Updated by:       dmitry@php.net
 Reported By:      crywolf at kyndimarion dot net
-Status:           Assigned
+Status:           Closed
 Bug Type:         Class/Object related
 Operating System: *
 PHP Version:      5CVS-2005-08-05
 Assigned To:      dmitry
 New Comment:

Fixed in CVS HEAD.


Previous Comments:
------------------------------------------------------------------------

[2005-08-05 00:04:43] tony2001@php.net

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-04 23:49:03] crywolf at kyndimarion dot net

Description:
------------
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:
---------------
<?php
error_reporting(E_ALL);

class Foo {
var $bar = "bat";
}

$foo = new Foo;
var_dump($foo);

$bar = (int)$foo;
var_dump($bar);

$baz = (float)$foo;
var_dump($baz);

?>


Expected result:
----------------
object(Foo)#1 (1) {
  ["bar"]=>
  string(3) "bat"
}
int(1)
float(1)

Actual result:
--------------
object(Foo)#1 (1) {
  ["bar"]=>
  string(3) "bat"
}
object(Foo)#1 (1) {
  ["bar"]=>
  string(3) "bat"
}

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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=33999&edit=1


Thread (3 messages)

« previous php.bugs (#83006) next »