]> granicus.if.org Git - php/commitdiff
Fixed bug #33999 (object remains object when cast to int)
authorDmitry Stogov <dmitry@php.net>
Fri, 5 Aug 2005 09:02:14 +0000 (09:02 +0000)
committerDmitry Stogov <dmitry@php.net>
Fri, 5 Aug 2005 09:02:14 +0000 (09:02 +0000)
NEWS
Zend/tests/bug33999.phpt [new file with mode: 0755]
Zend/zend_operators.c

diff --git a/NEWS b/NEWS
index dbb772a085060cf5ee578615e3d939458991e6ba..412feb99e34881afa4f6177098f48fe8f082974f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? ??? 2005, PHP 5.1
+- Fixed bug #33999 (object remains object when cast to int). (Dmitry)
 - Fixed bug #33989 (extract($GLOBALS,EXTR_REFS) crashes PHP). (Dmitry)
 - Fixed bug #33967 (misuse of Exception constructor doesn't display errorfile).
   (Jani)
diff --git a/Zend/tests/bug33999.phpt b/Zend/tests/bug33999.phpt
new file mode 100755 (executable)
index 0000000..1946280
--- /dev/null
@@ -0,0 +1,30 @@
+--TEST--
+Bug #33999 (object remains object when cast to int)
+--INI--
+error_reporting=4095
+--FILE--
+<?php
+class Foo {
+  public $bar = "bat";
+}
+
+$foo = new Foo;
+var_dump($foo);
+
+$bar = (int)$foo;
+var_dump($bar);
+
+$baz = (float)$foo;
+var_dump($baz);
+?>
+--EXPECTF--
+object(Foo)#1 (1) {
+  ["bar"]=>
+  string(3) "bat"
+}
+
+Notice: Object of class Foo could not be converted to int in %sbug33999.php on line 9
+int(1)
+
+Notice: Object of class Foo could not be converted to double in %sbug33999.php on line 12
+float(1)
index 1590e35a040cf146030dbf60aeb7a396be96568b..509f9e231581f284285cb2bfdcc9058d6ce4089b 100644 (file)
@@ -338,13 +338,12 @@ ZEND_API void convert_to_long_base(zval *op, int base)
                                        if (ht) {
                                                retval = (zend_hash_num_elements(ht)?1:0);
                                        }
-                                       zval_dtor(op);
-                                       ZVAL_LONG(op, retval);
-                                       return;
                                } else {
-                                       /* we cannot convert it to long */
-                                       return;
+                                       zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name);
                                }
+                               zval_dtor(op);
+                               ZVAL_LONG(op, retval);
+                               return;
                        }
                default:
                        zend_error(E_WARNING, "Cannot convert to ordinal value");
@@ -1319,7 +1318,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                zendi_smart_strcmp(result, op1, op2);
                COMPARE_RETURN_AND_FREE(SUCCESS);
        }
-       
+
        if (op1->type == IS_BOOL || op2->type == IS_BOOL
                || op1->type == IS_NULL || op2->type == IS_NULL) {
                zendi_convert_to_boolean(op1, op1_copy, result);