Browse Source

Fixed bug #33999 (object remains object when cast to int)

PHP-5.1
Dmitry Stogov 21 years ago
parent
commit
c10d6d3c89
  1. 1
      NEWS
  2. 30
      Zend/tests/bug33999.phpt
  3. 11
      Zend/zend_operators.c

1
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)

30
Zend/tests/bug33999.phpt

@ -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)

11
Zend/zend_operators.c

@ -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);

Loading…
Cancel
Save