- fix #49274, filter_var does not accept object without a toString implementation

This commit is contained in:
Pierre Joye 2009-09-05 17:35:26 +00:00
parent 7713cc89d9
commit b1f10764f9
2 changed files with 23 additions and 0 deletions

View File

@ -379,6 +379,19 @@ static void php_zval_filter(zval **value, long filter, long flags, zval *options
if (copy) {
SEPARATE_ZVAL(value);
}
/* #49274, fatal error with object without a toString method
Fails nicely instead of getting a recovarable fatal error. */
if (Z_TYPE_PP(value) == IS_OBJECT) {
zend_class_entry *ce;
ce = Z_OBJCE_PP(value);
if (!ce->__tostring) {
ZVAL_FALSE(*value);
return;
}
}
/* Here be strings */
convert_to_string(*value);

View File

@ -0,0 +1,10 @@
--TEST--
#49274, fatal error when an object does not implement toString
--SKIPIF--
<?php if (!extension_loaded("filter")) die("skip"); ?>
--FILE--
<?php
var_dump(filter_var(new stdClass, FILTER_VALIDATE_EMAIL));
?>
--EXPECTF--
bool(false)