From: Pierre Joye Date: Sat, 5 Sep 2009 17:35:26 +0000 (+0000) Subject: - fix #49274, filter_var does not accept object without a toString implementation X-Git-Tag: php-5.2.11RC3~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d17f0c2cc7ee43c46c58e3c3a8f618c501a2745;p=php - fix #49274, filter_var does not accept object without a toString implementation --- diff --git a/ext/filter/filter.c b/ext/filter/filter.c index e0c99a284c..afa9623b90 100644 --- a/ext/filter/filter.c +++ b/ext/filter/filter.c @@ -316,6 +316,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); diff --git a/ext/filter/tests/bug49274.phpt b/ext/filter/tests/bug49274.phpt new file mode 100644 index 0000000000..c87e6be1c7 --- /dev/null +++ b/ext/filter/tests/bug49274.phpt @@ -0,0 +1,10 @@ +--TEST-- +#49274, fatal error when an object does not implement toString +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(false)