From b00cd68d7419bea8d8155ae585b85cf4f5fe8897 Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 1 Mar 2015 02:37:57 +0000 Subject: [PATCH 01/13] Fixed PDORow behaviour and message. --- ext/pdo/pdo_stmt.c | 7 ++++--- ext/pdo/tests/pdo_036.phpt | 32 ++++++++++++++++++++++---------- ext/pdo/tests/pdorow.phpt | 18 ++++++++++++++++-- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index c6ebc37ec2283..947428789321f 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -113,9 +113,10 @@ ZEND_END_ARG_INFO() RETURN_FALSE; \ } \ -static PHP_FUNCTION(dbstmt_constructor) /* {{{ */ +static PHP_FUNCTION(dbrow_constructor) /* {{{ */ { - php_error_docref(NULL, E_ERROR, "You should not create a PDOStatement manually"); +// php_error_docref(NULL, E_ERROR, "You should not create a PDOStatement manually"); + zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually"); } /* }}} */ @@ -2640,7 +2641,7 @@ static union _zend_function *row_get_ctor(zend_object *object) ctor.type = ZEND_INTERNAL_FUNCTION; ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0); ctor.scope = pdo_row_ce; - ctor.handler = ZEND_FN(dbstmt_constructor); + ctor.handler = ZEND_FN(dbrow_constructor); ctor.fn_flags = ZEND_ACC_PUBLIC; return (union _zend_function*)&ctor; diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt index 55c88762ba3ea..16a1597f3633f 100644 --- a/ext/pdo/tests/pdo_036.phpt +++ b/ext/pdo/tests/pdo_036.phpt @@ -7,17 +7,29 @@ Testing PDORow and PDOStatement instances with Reflection $instance = new reflectionclass('pdostatement'); $x = $instance->newInstance(); -var_dump($x); -$instance = new reflectionclass('pdorow'); -$x = $instance->newInstance(); -var_dump($x); +if ($x instanceof pdostatement) { + echo "Ok".PHP_EOL; +} +else { + echo "Failed to create instance of pdostatment"; +} -?> ---EXPECTF-- -object(PDOStatement)#%d (1) { - [%u|b%"queryString"]=> - NULL +try { + $instance = new reflectionclass('pdorow'); + $x = $instance->newInstance(); + echo "Failed to throw exception: ".var_export($x, true); +} +catch(PDOException $pe) { + if ($pe->getMessage() != "You may not create a PDORow manually") { + echo "PDOException has wrong message."; + } + else { + echo "Ok".PHP_EOL; + } } -Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %spdo_036.php on line %d +?> +--EXPECTF-- +Ok +Ok diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt index bcfd8ff229d01..3b4660423c874 100644 --- a/ext/pdo/tests/pdorow.phpt +++ b/ext/pdo/tests/pdorow.phpt @@ -5,8 +5,22 @@ Trying instantiate a PDORow object manually --FILE-- getMessage() != "You may not create a PDORow manually") { + echo "PDOException has wrong message."; + } + else { + echo "Ok".PHP_EOL; + } +} +catch(\Exception $e) { + echo "Failed to "; +} ?> --EXPECTF-- -Fatal error: PDORow::__construct(): You should not create a PDOStatement manually in %s on line %d +Ok From 043a02605f7bbf03f8a085354bfa617689a919d3 Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 1 Mar 2015 13:06:58 +0000 Subject: [PATCH 02/13] Fixed ReflectionFunction, ReflectionMethod and ReflectionParameter. --- ext/pdo/tests/pdorow.phpt | 2 +- ext/reflection/php_reflection.c | 55 ++++++++++++------- .../ReflectionFunction_construct.001.phpt | 39 ++++++++++--- .../tests/ReflectionMethod_006.phpt | 31 +++++------ .../ReflectionMethod_constructor_error2.phpt | 39 ++++++++++--- ...nParameter_invalidMethodInConstructor.phpt | 21 ++++++- 6 files changed, 133 insertions(+), 54 deletions(-) diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt index 3b4660423c874..fca40a1ee1a1a 100644 --- a/ext/pdo/tests/pdorow.phpt +++ b/ext/pdo/tests/pdorow.phpt @@ -18,7 +18,7 @@ catch(PDOException $pe) { } } catch(\Exception $e) { - echo "Failed to "; + echo "Exception throw was not of type PDOException instead was ".get_class($e).PHP_EOL; } ?> diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index 80e04046ed17e..a01a0d67c56a5 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1576,6 +1576,8 @@ ZEND_METHOD(reflection_function, __construct) zend_function *fptr; char *name_str; size_t name_len; + int rv; + zend_error_handling zeh; object = getThis(); intern = Z_REFLECTION_P(object); @@ -1586,27 +1588,32 @@ ZEND_METHOD(reflection_function, __construct) if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "O", &closure, zend_ce_closure) == SUCCESS) { fptr = (zend_function*)zend_get_closure_method_def(closure); Z_ADDREF_P(closure); - } else if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == SUCCESS) { - char *nsname; - - lcname = zend_str_tolower_dup(name_str, name_len); - - /* Ignore leading "\" */ - nsname = lcname; - if (lcname[0] == '\\') { - nsname = &lcname[1]; - name_len--; - } - - if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { + } else { + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + if (rv == SUCCESS) { + char *nsname; + lcname = zend_str_tolower_dup(name_str, name_len); + + /* Ignore leading "\" */ + nsname = lcname; + if (lcname[0] == '\\') { + nsname = &lcname[1]; + name_len--; + } + + if ((fptr = zend_hash_str_find_ptr(EG(function_table), nsname, name_len)) == NULL) { + efree(lcname); + zend_throw_exception_ex(reflection_exception_ptr, 0, + "Function %s() does not exist", name_str); + return; + } efree(lcname); - zend_throw_exception_ex(reflection_exception_ptr, 0, - "Function %s() does not exist", name_str); + } else { + //Exception has been thrown. return; } - efree(lcname); - } else { - return; } ZVAL_STR_COPY(&name, fptr->common.function_name); @@ -2128,10 +2135,14 @@ ZEND_METHOD(reflection_parameter, __construct) zend_class_entry *ce = NULL; zend_bool is_closure = 0; zend_bool is_invoke = 0; + zend_error_handling zeh; + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &reference, ¶meter) == FAILURE) { + zend_restore_error_handling(&zeh TSRMLS_CC); return; } + zend_restore_error_handling(&zeh TSRMLS_CC); object = getThis(); intern = Z_REFLECTION_P(object); @@ -2712,7 +2723,13 @@ ZEND_METHOD(reflection_method, __construct) zval ztmp; if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + zend_error_handling zeh; + int rv; + + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + if (rv == FAILURE) { return; } if ((tmp = strstr(name_str, "::")) == NULL) { diff --git a/ext/reflection/tests/ReflectionFunction_construct.001.phpt b/ext/reflection/tests/ReflectionFunction_construct.001.phpt index c8e0a17a9d4b9..90259ac9976a5 100644 --- a/ext/reflection/tests/ReflectionFunction_construct.001.phpt +++ b/ext/reflection/tests/ReflectionFunction_construct.001.phpt @@ -6,18 +6,41 @@ Steve Seear --FILE-- getMessage().PHP_EOL; +} try { $a = new ReflectionFunction('nonExistentFunction'); } catch (Exception $e) { - echo $e->getMessage(); + echo $e->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction(); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction(1, 2); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + $a = new ReflectionFunction([]); } -$a = new ReflectionFunction(); -$a = new ReflectionFunction(1, 2); +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + ?> --EXPECTF-- -Warning: ReflectionFunction::__construct() expects parameter 1 to be string, array given in %s on line %d +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given Function nonExistentFunction() does not exist -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 0 given in %s on line %d - -Warning: ReflectionFunction::__construct() expects exactly 1 parameter, 2 given in %s on line %d +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionFunction::__construct() expects exactly 1 parameter, 2 given +Ok - ReflectionFunction::__construct() expects parameter 1 to be string, array given diff --git a/ext/reflection/tests/ReflectionMethod_006.phpt b/ext/reflection/tests/ReflectionMethod_006.phpt index a5164190ca67d..0b8228989c7bb 100644 --- a/ext/reflection/tests/ReflectionMethod_006.phpt +++ b/ext/reflection/tests/ReflectionMethod_006.phpt @@ -6,8 +6,18 @@ Steve Seear --FILE-- getMessage().PHP_EOL; +} +try { + new ReflectionMethod('a', 'b', 'c'); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} class C { public function f() {} @@ -35,21 +45,8 @@ var_dump($rm->getName(1)); ?> --EXPECTF-- -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line %d -object(ReflectionMethod)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given Warning: ReflectionMethod::isFinal() expects exactly 0 parameters, 1 given in %s on line %d NULL diff --git a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt index 1c2d3a138fcaf..85f8097825482 100644 --- a/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt +++ b/ext/reflection/tests/ReflectionMethod_constructor_error2.phpt @@ -16,22 +16,47 @@ class TestClass try { echo "Too few arguments:\n"; $methodInfo = new ReflectionMethod(); -} catch (Exception $e) { - print $e->__toString(); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } try { echo "\nToo many arguments:\n"; $methodInfo = new ReflectionMethod("TestClass", "foo", true); -} catch (Exception $e) { - print $e->__toString(); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid class + $methodInfo = new ReflectionMethod("InvalidClassName", "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + +try { + //invalid 1st param + $methodInfo = new ReflectionMethod([], "foo"); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try{ + //invalid 2nd param + $methodInfo = new ReflectionMethod("TestClass", []); +} catch (ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; } ?> --EXPECTF-- Too few arguments: - -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 0 given in %s on line 12 +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 0 given Too many arguments: +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 3 given +Ok - Class InvalidClassName does not exist +Ok - The parameter class is expected to be either a string or an object +Ok - ReflectionMethod::__construct() expects exactly 1 parameter, 2 given -Warning: ReflectionMethod::__construct() expects exactly 1 parameter, 3 given in %s on line 18 diff --git a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt index 3118c17be8b37..1775dee514419 100644 --- a/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt +++ b/ext/reflection/tests/ReflectionParameter_invalidMethodInConstructor.phpt @@ -6,7 +6,7 @@ ReflectionParameter::__construct(): Invalid method as constructor // Invalid class name try { new ReflectionParameter (array ('A', 'b'), 0); -} catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } +} catch (ReflectionException $e) { echo $e->getMessage()."\n"; } // Invalid class method try { @@ -18,14 +18,31 @@ try { new ReflectionParameter (array (new C, 'b'), 0); } catch (ReflectionException $e) { echo $e->getMessage ()."\n"; } -echo "Done.\n"; class C { } +try { + new ReflectionParameter(array ('A', 'b')); +} +catch(ReflectionException $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +try { + new ReflectionParameter(0, 0); +} +catch(ReflectionException $e) { + printf( "Ok - %s\n", $e->getMessage()); +} + +echo "Done.\n"; + ?> --EXPECTF-- Class A does not exist Method C::b() does not exist Method C::b() does not exist +Ok - ReflectionParameter::__construct() expects exactly 2 parameters, 1 given +Ok - The parameter class is expected to be either a string, an array(class, method) or a callable object Done. From a519838ece18dd1babce5b6683b04e99e7816184 Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 1 Mar 2015 13:20:07 +0000 Subject: [PATCH 03/13] Fixed ReflectionExtension and ReflectionProperty. --- ext/reflection/php_reflection.c | 25 ++++++++-- ...ReflectionExtension_constructor_error.phpt | 30 +++++++++-- .../tests/ReflectionProperty_error.phpt | 50 +++++++++---------- 3 files changed, 71 insertions(+), 34 deletions(-) diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index a01a0d67c56a5..6c96acb457839 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -4802,7 +4802,14 @@ ZEND_METHOD(reflection_property, __construct) zend_property_info *property_info = NULL; property_reference *reference; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len) == FAILURE) { + int rv; + zend_error_handling zeh; + + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "zs", &classname, &name_str, &name_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == FAILURE) { return; } @@ -5197,9 +5204,15 @@ ZEND_METHOD(reflection_extension, __construct) zend_module_entry *module; char *name_str; size_t name_len; + int rv; + zend_error_handling zeh; ALLOCA_FLAG(use_heap) - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == FAILURE) { return; } @@ -5566,8 +5579,14 @@ ZEND_METHOD(reflection_zend_extension, __construct) zend_extension *extension; char *name_str; size_t name_len; + int rv; + zend_error_handling zeh; + + zend_replace_error_handling(EH_THROW, reflection_exception_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len); + zend_restore_error_handling(&zeh TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &name_str, &name_len) == FAILURE) { + if (rv == FAILURE) { return; } diff --git a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt index 9eae206c5034b..f731ab51cc7db 100644 --- a/ext/reflection/tests/ReflectionExtension_constructor_error.phpt +++ b/ext/reflection/tests/ReflectionExtension_constructor_error.phpt @@ -5,12 +5,32 @@ Gerrit "Remi" te Sligte Leon Luijkx --FILE-- getMessage().PHP_EOL; +} + +try { + $obj = new ReflectionExtension('foo', 'bar'); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try { + $obj = new ReflectionExtension([]); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + ?> ==DONE== --EXPECTF-- -Warning: ReflectionExtension::__construct() expects exactly %d parameter, %d given in %s.php on line %d -bool(true) +Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given +Ok - ReflectionExtension::__construct() expects exactly %d parameter, %d given +Ok - ReflectionExtension::__construct() expects parameter 1 to be string, array given ==DONE== diff --git a/ext/reflection/tests/ReflectionProperty_error.phpt b/ext/reflection/tests/ReflectionProperty_error.phpt index 56de6e1f2e8af..d3910296b58bf 100644 --- a/ext/reflection/tests/ReflectionProperty_error.phpt +++ b/ext/reflection/tests/ReflectionProperty_error.phpt @@ -7,9 +7,27 @@ class C { public static $p; } -var_dump(new ReflectionProperty()); -var_dump(new ReflectionProperty('C::p')); -var_dump(new ReflectionProperty('C', 'p', 'x')); +try { + new ReflectionProperty(); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} +try { + new ReflectionProperty('C::p'); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + +try { + new ReflectionProperty('C', 'p', 'x'); +} +catch(ReflectionException $re) { + echo "Ok - ".$re->getMessage().PHP_EOL; +} + + $rp = new ReflectionProperty('C', 'p'); var_dump($rp->getName(1)); var_dump($rp->isPrivate(1)); @@ -21,29 +39,9 @@ var_dump($rp->isDefault(1)); ?> --EXPECTF-- -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 0 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 1 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} - -Warning: ReflectionProperty::__construct() expects exactly 2 parameters, 3 given in %s on line %d -object(ReflectionProperty)#%d (2) { - ["name"]=> - string(0) "" - ["class"]=> - string(0) "" -} +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 0 given +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 1 given +Ok - ReflectionProperty::__construct() expects exactly 2 parameters, 3 given Warning: ReflectionProperty::getName() expects exactly 0 parameters, 1 given in %s on line %d NULL From c57bde7c9e2f4ac3e93f096eaa93d4ab0133915d Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 1 Mar 2015 13:44:55 +0000 Subject: [PATCH 04/13] Fixed SplFixedArray and tests. --- ext/spl/spl_fixedarray.c | 7 ++++ .../SplFixedArray__construct_param_array.phpt | 9 ++++- ...SplFixedArray__construct_param_string.phpt | 9 ++++- ...edArray_construct_param_SplFixedArray.phpt | 13 +++--- ext/spl/tests/fixedarray_005.phpt | 10 ++++- ext/spl/tests/fixedarray_009.phpt | 10 +++-- ext/spl/tests/fixedarray_015.phpt | 40 ++----------------- 7 files changed, 48 insertions(+), 50 deletions(-) diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index cd83a17b56f1c..dcac83d60df5c 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -561,6 +561,13 @@ SPL_METHOD(SplFixedArray, __construct) spl_fixedarray_object *intern; zend_long size = 0; + int rv; + zend_error_handling zeh; + +// zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC); +// rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size); +// zend_restore_error_handling(&zeh TSRMLS_CC); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) { return; } diff --git a/ext/spl/tests/SplFixedArray__construct_param_array.phpt b/ext/spl/tests/SplFixedArray__construct_param_array.phpt index 1d78695d4a9a3..aa5933ebdbef2 100644 --- a/ext/spl/tests/SplFixedArray__construct_param_array.phpt +++ b/ext/spl/tests/SplFixedArray__construct_param_array.phpt @@ -5,8 +5,13 @@ PHPNW Test Fest 2009 - Jordan Hatch --FILE-- getMessage().PHP_EOL; +} ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, array given in %s on line %d \ No newline at end of file +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, array given \ No newline at end of file diff --git a/ext/spl/tests/SplFixedArray__construct_param_string.phpt b/ext/spl/tests/SplFixedArray__construct_param_string.phpt index 99742e3eb7376..411d7402df044 100644 --- a/ext/spl/tests/SplFixedArray__construct_param_string.phpt +++ b/ext/spl/tests/SplFixedArray__construct_param_string.phpt @@ -4,9 +4,14 @@ SplFixedArray::__construct() with string passed as parameter. PHPNW Test Fest 2009 - Jordan Hatch --FILE-- getMessage().PHP_EOL; +} -$array = new SplFixedArray( "string" ); ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given in %s on line %d +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, %unicode_string_optional% given diff --git a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt index e91f110cd469b..10d4c64a0c524 100644 --- a/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt +++ b/ext/spl/tests/SplFixedArray_construct_param_SplFixedArray.phpt @@ -4,10 +4,13 @@ Create an SplFixedArray using an SplFixedArray object. Philip Norton philipnorton42@gmail.com --FILE-- getMessage().PHP_EOL; +} + ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d -object(SplFixedArray)#1 (0) { -} \ No newline at end of file +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given diff --git a/ext/spl/tests/fixedarray_005.phpt b/ext/spl/tests/fixedarray_005.phpt index fdd78f06a2502..72970a9a1f900 100644 --- a/ext/spl/tests/fixedarray_005.phpt +++ b/ext/spl/tests/fixedarray_005.phpt @@ -5,8 +5,14 @@ SPL: FixedArray: Trying to instantiate passing object to constructor parameter $b = new stdClass; -$a = new SplFixedArray($b); +try { + $a = new SplFixedArray($b); +} +catch(InvalidArgumentException $iae) { + echo "Ok - ".$iae->getMessage().PHP_EOL; +} + ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, object given in %s on line %d +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, object given diff --git a/ext/spl/tests/fixedarray_009.phpt b/ext/spl/tests/fixedarray_009.phpt index c386fc638e300..d67c7ccb6983b 100644 --- a/ext/spl/tests/fixedarray_009.phpt +++ b/ext/spl/tests/fixedarray_009.phpt @@ -3,8 +3,12 @@ SPL: FixedArray: Trying to instantiate passing string to construtor parameter --FILE-- getMessage().PHP_EOL; +} ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given diff --git a/ext/spl/tests/fixedarray_015.phpt b/ext/spl/tests/fixedarray_015.phpt index 6e31a42532c00..f12d83bb39188 100644 --- a/ext/spl/tests/fixedarray_015.phpt +++ b/ext/spl/tests/fixedarray_015.phpt @@ -3,47 +3,15 @@ SPL: FixedArray: accessing uninitialized array --FILE-- getMessage(), "\n"; -} -try { - $a[1] = 1; -} catch (Exception $e) { - echo $e->getMessage(), "\n"; -} try { - var_dump(count($a[1])); -} catch (Exception $e) { - echo $e->getMessage(), "\n"; + $a = new SplFixedArray(''); } -try { - var_dump($a->getSize()); -} catch (Exception $e) { - echo $e->getMessage(), "\n"; -} -try { - foreach ($a as $v) { - } -} catch (Exception $e) { - echo $e->getMessage(), "\n"; -} -try { - var_dump($a->setSize(10)); -} catch (Exception $e) { - echo $e->getMessage(), "\n"; +catch(InvalidArgumentException $iae) { + echo "Ok - ".$iae->getMessage().PHP_EOL; } echo "Done\n"; ?> --EXPECTF-- -Warning: SplFixedArray::__construct() expects parameter 1 to be integer, string given in %s on line %d -Index invalid or out of range -Index invalid or out of range -Index invalid or out of range -int(0) -bool(true) +Ok - SplFixedArray::__construct() expects parameter 1 to be integer, string given Done From 99dae96dc0041f856ae066b3f572495da609d28e Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 13:59:48 +0000 Subject: [PATCH 05/13] Converted intl extension to use IntlException in constructors. --- .../breakiterator/breakiterator_methods.cpp | 4 +- .../calendar/gregoriancalendar_methods.cpp | 38 ++++++------ ext/intl/collator/collator_create.c | 12 ++-- ext/intl/dateformat/dateformat_create.cpp | 20 +++--- ext/intl/formatter/formatter_main.c | 14 ++--- ext/intl/intl_common.h | 2 + ext/intl/intl_data.h | 4 +- ext/intl/intl_error.c | 57 ++++++++++++++--- ext/intl/intl_error.h | 6 ++ ext/intl/msgformat/msgformat.c | 16 ++--- ext/intl/msgformat/msgformat_class.c | 4 +- .../resourcebundle/resourcebundle_class.c | 14 ++--- ext/intl/spoofchecker/spoofchecker_create.c | 2 +- ext/intl/tests/bug62017.phpt | 12 ++-- ext/intl/tests/formatter_fail.phpt | 53 +++++++++------- ext/intl/tests/formatter_format.phpt | 9 ++- .../gregoriancalendar___construct_error.phpt | 22 ++++--- ext/intl/tests/msgfmt_fail.phpt | 61 +++++++++++-------- ext/intl/tests/msgfmt_parse.phpt | 14 +++-- ext/intl/tests/resourcebundle_create.phpt | 29 +++++---- .../transliterator/transliterator_methods.c | 8 +-- 21 files changed, 250 insertions(+), 151 deletions(-) diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp index baab5a682d68e..02d228653a61c 100644 --- a/ext/intl/breakiterator/breakiterator_methods.cpp +++ b/ext/intl/breakiterator/breakiterator_methods.cpp @@ -162,12 +162,12 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text) BREAKITER_METHOD_FETCH_OBJECT; ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio)); - INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText"); + INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText", 0); bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio)); utext_close(ut); /* ICU shallow clones the UText */ INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling " - "BreakIterator::setText()"); + "BreakIterator::setText()", 0); /* When ICU clones the UText, it does not copy the buffer, so we have to * keep the string buffer around by holding a reference to its zval. This diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 2ae573722793d..69bae08e062bc 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -36,7 +36,7 @@ static inline GregorianCalendar *fetch_greg(Calendar_object *co) { return (GregorianCalendar*)co->ucal; } -static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) +static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { zval *tz_object = NULL; zval args_a[6] = {0}, @@ -51,8 +51,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) // parameter number validation / variant determination if (ZEND_NUM_ARGS() > 6 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: too many arguments", 0); + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: too many arguments", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -60,9 +60,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: no variant with 4 arguments " - "(excluding trailing NULLs)", 0); + "(excluding trailing NULLs)", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -71,8 +71,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) if (variant <= 2) { if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2), "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: bad arguments", 0); + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -80,8 +80,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(), "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], &largs[5]) == FAILURE) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: bad arguments", 0); + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -104,8 +104,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); if (U_FAILURE(status)) { - intl_error_set(NULL, status, "intlgregcal_create_instance: error " - "creating ICU GregorianCalendar from time zone and locale", 0); + intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from time zone and locale", 0, is_constructor); if (gcal) { delete gcal; } @@ -117,9 +117,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: at least one of the arguments" - " has an absolute value that is too large", 0); + " has an absolute value that is too large", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -137,8 +137,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) status); } if (U_FAILURE(status)) { - intl_error_set(NULL, status, "intlgregcal_create_instance: error " - "creating ICU GregorianCalendar from date", 0); + intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from date", 0, is_constructor); if (gcal) { delete gcal; } @@ -154,10 +154,10 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) strlen(tzinfo->name), US_INV); #endif if (tzstr.isBogus()) { - intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: could not create UTF-8 string " "from PHP's default timezone name (see date_default_timezone_get())", - 0); + 0, is_constructor); delete gcal; Z_OBJ_P(return_value) = NULL; return; @@ -179,7 +179,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) object_init_ex(return_value, GregorianCalendar_ce_ptr); ZVAL_COPY_VALUE(&orig, return_value); - _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zval_dtor(&orig); @@ -194,7 +194,7 @@ U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) return_value = getThis(); //changes this to IS_NULL (without first destroying) if there's an error - _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c index b2058422c2282..7631d76ff426e 100644 --- a/ext/intl/collator/collator_create.c +++ b/ext/intl/collator/collator_create.c @@ -25,7 +25,7 @@ #include "intl_data.h" /* {{{ */ -static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) +static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; size_t locale_len = 0; @@ -38,8 +38,8 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) if( zend_parse_parameters( ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "collator_create: unable to parse input params", 0 ); + intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "collator_create: unable to parse input params", 0, is_constructor ); zval_dtor(return_value); RETURN_NULL(); } @@ -53,7 +53,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); - INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); + INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator", is_constructor); } /* }}} */ @@ -63,7 +63,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) PHP_FUNCTION( collator_create ) { object_init_ex( return_value, Collator_ce_ptr ); - collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } /* }}} */ @@ -75,7 +75,7 @@ PHP_METHOD( Collator, __construct ) zval orig_this = *getThis(); return_value = getThis(); - collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index f8cf77641f6c9..9d6d5f4e97a38 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -36,7 +36,7 @@ extern "C" { #include "dateformat_helpers.h" /* {{{ */ -static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) +static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { zval *object; @@ -64,8 +64,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs", &locale_str, &locale_len, &date_type, &time_type, &timezone_zv, &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " - "unable to parse input parameters", 0); + intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " + "unable to parse input parameters", 0, is_constructor); Z_OBJ_P(return_value) = NULL; return; } @@ -79,6 +79,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { + // This is __construct being called on an instance - it is not + // a constructor. intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0); return; @@ -110,8 +112,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { /* object construction -> only set global error */ - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " - "error converting pattern to UTF-16", 0); + intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " + "error converting pattern to UTF-16", 0, is_constructor); goto error; } } @@ -139,8 +141,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) df->adoptTimeZone(timezone); } } else { - intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " - "formatter creation failed", 0); + intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " + "formatter creation failed", 0, is_constructor); goto error; } @@ -175,7 +177,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) U_CFUNC PHP_FUNCTION( datefmt_create ) { object_init_ex( return_value, IntlDateFormatter_ce_ptr ); - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -192,7 +194,7 @@ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct ) /* return_value param is being changed, therefore we will always return * NULL here */ return_value = getThis(); - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index 60db673ff2849..c8ca65da272f2 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -25,7 +25,7 @@ #include "intl_convert.h" /* {{{ */ -static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) +static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; char* pattern = NULL; @@ -39,8 +39,8 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s", &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "numfmt_create: unable to parse input parameters", 0 ); + intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "numfmt_create: unable to parse input parameters", 0, is_constructor ); Z_OBJ_P(return_value) = NULL; return; } @@ -52,7 +52,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo)); - INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16"); + INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16", is_constructor); } if(locale_len == 0) { @@ -66,7 +66,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) efree(spattern); } - INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed"); + INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed", is_constructor); } /* }}} */ @@ -78,7 +78,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) PHP_FUNCTION( numfmt_create ) { object_init_ex( return_value, NumberFormatter_ce_ptr ); - numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -93,7 +93,7 @@ PHP_METHOD( NumberFormatter, __construct ) zval orig_this = *getThis(); return_value = getThis(); - numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); diff --git a/ext/intl/intl_common.h b/ext/intl/intl_common.h index a49794648d9ac..61da2738d195a 100644 --- a/ext/intl/intl_common.h +++ b/ext/intl/intl_common.h @@ -41,4 +41,6 @@ #define INTL_Z_STRVAL_P(str) (UChar*) Z_STRVAL_P(str) #define INTL_Z_STRLEN_P(str) UCHARS( Z_STRLEN_P(str) ) +extern zend_class_entry *IntlException_ce_ptr; + #endif /* INTL_COMMON_H */ diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h index 6001aa128513c..c49214ffcd622 100644 --- a/ext/intl/intl_data.h +++ b/ext/intl/intl_data.h @@ -64,11 +64,11 @@ typedef struct _intl_data { } /* Check status, if error - destroy value and exit */ -#define INTL_CTOR_CHECK_STATUS(obj, msg) \ +#define INTL_CTOR_CHECK_STATUS(obj, msg, forceException) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ - intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ + intl_errors_set_custom_msg_ex( INTL_DATA_ERROR_P((obj)), msg, 0, forceException ); \ /* yes, this is ugly, but it alreay is */ \ if (return_value != getThis()) { \ zval_dtor(return_value); \ diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index 28a2a244e245d..8ea5e7b4cf129 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -29,7 +29,7 @@ ZEND_EXTERN_MODULE_GLOBALS( intl ) -static zend_class_entry *IntlException_ce_ptr; +zend_class_entry *IntlException_ce_ptr; /* {{{ intl_error* intl_g_error_get() * Return global error structure. @@ -102,15 +102,26 @@ void intl_error_reset( intl_error* err ) * Set last error message to msg copying it if needed. */ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) +{ + intl_error_set_custom_msg_ex( err, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) + * Set last error message to msg copying it if needed. + */ +void intl_error_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if( !msg ) return; if( !err ) { - if( INTL_G( error_level ) ) - php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); - if( INTL_G( use_exceptions ) ) + if ( forceException || INTL_G( use_exceptions ) ) { zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg ); + } else if( INTL_G( error_level ) ) { + php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); + } } if( !err && !( err = intl_g_error_get( ) ) ) return; @@ -181,19 +192,39 @@ UErrorCode intl_error_get_code( intl_error* err ) * Set error code and message. */ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) +{ + intl_error_set_ex( err, code, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) + * Set error code and message. + */ +void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_error_set_code( err, code ); - intl_error_set_custom_msg( err, msg, copyMsg ); + intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); } /* }}} */ + /* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) * Set error code and message. */ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) +{ + intl_errors_set_ex( err, code, msg, copyMsg, 0 ); +} +/* }}} */ + +/* {{{ void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg ) + * Set error code and message. + */ +void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_errors_set_code( err, code ); - intl_errors_set_custom_msg( err, msg, copyMsg ); + intl_errors_set_custom_msg_ex( err, msg, copyMsg, forceException ); } /* }}} */ @@ -211,14 +242,24 @@ void intl_errors_reset( intl_error* err ) /* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) */ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) +{ + intl_errors_set_custom_msg_ex( err, msg, copyMsg, 0 ); +} +/* }}} */ + + +/* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) + */ +void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if(err) { - intl_error_set_custom_msg( err, msg, copyMsg ); + intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); } - intl_error_set_custom_msg( NULL, msg, copyMsg ); + intl_error_set_custom_msg_ex( NULL, msg, copyMsg, forceException ); } /* }}} */ + /* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code ) */ void intl_errors_set_code( intl_error* err, UErrorCode err_code ) diff --git a/ext/intl/intl_error.h b/ext/intl/intl_error.h index 02d62f0299666..4c9349b281493 100644 --- a/ext/intl/intl_error.h +++ b/ext/intl/intl_error.h @@ -36,15 +36,21 @@ void intl_error_init( intl_error* err ); void intl_error_reset( intl_error* err ); void intl_error_set_code( intl_error* err, UErrorCode err_code ); void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ); +void intl_error_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ); void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ); +void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ); + + UErrorCode intl_error_get_code( intl_error* err ); zend_string* intl_error_get_message( intl_error* err ); // Wrappers to synchonize object's and global error structures. void intl_errors_reset( intl_error* err ); void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ); +void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ); void intl_errors_set_code( intl_error* err, UErrorCode err_code ); void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ); +void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ); // Other error helpers smart_str intl_parse_error_to_string( UParseError* pe ); diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 707b38bd95cd0..34923f92a5cc9 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -26,7 +26,7 @@ #include "intl_convert.h" /* {{{ */ -static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) +static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char* locale; char* pattern; @@ -42,8 +42,8 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss", &locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_create: unable to parse input parameters", 0 ); + intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "msgfmt_create: unable to parse input parameters", 0, is_constructor ); Z_OBJ_P(return_value) = NULL; return; } @@ -54,7 +54,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16"); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16", is_constructor); } else { spattern_len = 0; spattern = NULL; @@ -66,7 +66,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format"); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format", is_constructor); } #endif @@ -84,7 +84,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) efree(spattern); } - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed", is_constructor); } /* }}} */ @@ -96,7 +96,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -111,7 +111,7 @@ PHP_METHOD( MessageFormatter, __construct ) zval orig_this = *getThis(); return_value = getThis(); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.c index 8d464c6ca48d6..1296d087e1e38 100644 --- a/ext/intl/msgformat/msgformat_class.c +++ b/ext/intl/msgformat/msgformat_class.c @@ -87,10 +87,10 @@ zend_object *MessageFormatter_object_clone(zval *object) if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo), "Failed to clone MessageFormatter object", 0); - zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object"); + zend_throw_exception_ex(IntlException_ce_ptr, 0, "Failed to clone MessageFormatter object"); } } else { - zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter"); + zend_throw_exception_ex(IntlException_ce_ptr, 0, "Cannot clone unconstructed MessageFormatter"); } return new_obj; } diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index b8d27c940af6d..60800fe1a99ee 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -74,7 +74,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce ) /* }}} */ /* {{{ ResourceBundle_ctor */ -static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) +static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) { const char *bundlename; size_t bundlename_len = 0; @@ -90,8 +90,8 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b", &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE ) { - intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "resourcebundle_ctor: unable to parse input parameters", 0 ); + intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "resourcebundle_ctor: unable to parse input parameters", 0, is_constructor ); Z_OBJ_P(return_value) = NULL; return; } @@ -108,7 +108,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } - INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle"); + INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle", is_constructor); if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { @@ -119,7 +119,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) bundlename ? bundlename : "(default data)", locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb))); - intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1); + intl_errors_set_custom_msg_ex(INTL_DATA_ERROR_P(rb), pbuf, 1, is_constructor); efree(pbuf); Z_OBJ_P(return_value) = NULL; } @@ -142,7 +142,7 @@ PHP_METHOD( ResourceBundle, __construct ) zval orig_this = *getThis(); return_value = getThis(); - resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zend_object_store_ctor_failed(Z_OBJ(orig_this)); @@ -157,7 +157,7 @@ proto ResourceBundle resourcebundle_create( string $locale [, string $bundlename PHP_FUNCTION( resourcebundle_create ) { object_init_ex( return_value, ResourceBundle_ce_ptr ); - resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); + resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c index d797015cf8de1..b56c840961df4 100644 --- a/ext/intl/spoofchecker/spoofchecker_create.c +++ b/ext/intl/spoofchecker/spoofchecker_create.c @@ -38,7 +38,7 @@ PHP_METHOD(Spoofchecker, __construct) SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co)); - INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker"); + INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker", 1); /* Single-script enforcement is on by default. This fails for languages like Japanese that legally use multiple scripts within a single word, diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt index 50aeae48061a4..e5c216c1e2a42 100644 --- a/ext/intl/tests/bug62017.phpt +++ b/ext/intl/tests/bug62017.phpt @@ -10,13 +10,15 @@ ini_set('intl.error_level', E_WARNING); var_dump( datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF", IntlDateFormatter::GREGORIAN, 'a')); -var_dump( +try { new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", - IntlDateFormatter::GREGORIAN, "\x80")); + IntlDateFormatter::GREGORIAN, "\x80"); +} +catch(IntlException $ie) { + echo $ie->getMessage().PHP_EOL; +} --EXPECTF-- Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d NULL - -Warning: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %s on line %d -NULL +datefmt_create: error converting pattern to UTF-16 diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt index 295f011008d6c..c45b113bdba38 100644 --- a/ext/intl/tests/formatter_fail.phpt +++ b/ext/intl/tests/formatter_fail.phpt @@ -12,16 +12,23 @@ function err($fmt) { } function crt($t, $l, $s) { - switch(true) { - case $t == "O": - return new NumberFormatter($l, $s); - break; - case $t == "C": - return NumberFormatter::create($l, $s); - break; - case $t == "P": - return numfmt_create($l, $s); - break; + try { + $fmt = null; + switch(true) { + case $t == "O": + $fmt = new NumberFormatter($l, $s); + break; + case $t == "C": + $fmt = NumberFormatter::create($l, $s); + break; + case $t == "P": + $fmt = numfmt_create($l, $s); + break; + } + err($fmt); + } + catch(IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; } } @@ -33,8 +40,13 @@ $args = array( array("en_US", NumberFormatter::PATTERN_RULEBASED), ); -$fmt = new NumberFormatter(); -err($fmt); +try { + $fmt = new NumberFormatter(); +} +catch(IntlException $ie) { + echo $ie->getMessage().PHP_EOL; +} + $fmt = numfmt_create(); err($fmt); $fmt = NumberFormatter::create(); @@ -42,11 +54,8 @@ err($fmt); foreach($args as $arg) { $fmt = crt("O", $arg[0], $arg[1]); - err($fmt); $fmt = crt("C", $arg[0], $arg[1]); - err($fmt); $fmt = crt("P", $arg[0], $arg[1]); - err($fmt); } ?> @@ -70,10 +79,10 @@ Warning: NumberFormatter::create() expects parameter 1 to be string, array given 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d -'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' -'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' -'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' +IE: numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR +IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR +IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR +IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR +IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR +IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR +IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR diff --git a/ext/intl/tests/formatter_format.phpt b/ext/intl/tests/formatter_format.phpt index 334ef49567cc2..0fa88681d95ae 100644 --- a/ext/intl/tests/formatter_format.phpt +++ b/ext/intl/tests/formatter_format.phpt @@ -50,7 +50,14 @@ function ut_main() $str_res .= "\nLocale is: $locale\n"; foreach( $styles as $style => $pattern ) { - $fmt = ut_nfmt_create( $locale, $style, $pattern ); + try { + $fmt = ut_nfmt_create( $locale, $style, $pattern ); + } + catch (IntlException $ie) { + //$str_res .= "IE:".$ie->getMessage()."\n"; + $str_res .= "Bad formatter!\n"; + continue; + } if(!$fmt) { $str_res .= "Bad formatter!\n"; diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt index 45229cf000fec..a28fa715e4241 100644 --- a/ext/intl/tests/gregoriancalendar___construct_error.phpt +++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt @@ -11,8 +11,18 @@ ini_set("intl.error_level", E_WARNING); var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7)); var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8)); var_dump(intlgregcal_create_instance(1,2,3,4)); -var_dump(new IntlGregorianCalendar(1,2,NULL,4)); -var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array())); +try { + new IntlGregorianCalendar(1,2,NULL,4); +} +catch (IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; +} +try { + new IntlGregorianCalendar(1,2,3,4,NULL,array()); +} +catch (IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; +} --EXPECTF-- @@ -26,10 +36,6 @@ NULL Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d NULL -Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d -NULL - +IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d - -Warning: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments in %s on line %d -NULL +IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt index bffb71c56d3aa..4b60b35abc2cf 100644 --- a/ext/intl/tests/msgfmt_fail.phpt +++ b/ext/intl/tests/msgfmt_fail.phpt @@ -13,16 +13,24 @@ function err($fmt) { } function crt($t, $l, $s) { - switch(true) { - case $t == "O": - return new MessageFormatter($l, $s); - break; - case $t == "C": - return MessageFormatter::create($l, $s); - break; - case $t == "P": - return msgfmt_create($l, $s); - break; + + try { + $fmt = null; + switch(true) { + case $t == "O": + $fmt = new MessageFormatter($l, $s); + break; + case $t == "C": + $fmt = MessageFormatter::create($l, $s); + break; + case $t == "P": + $fmt = msgfmt_create($l, $s); + break; + } + err($fmt); + } + catch (IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; } } @@ -35,32 +43,36 @@ $args = array( array("en_US", "\xD0"), ); -$fmt = new MessageFormatter(); -err($fmt); +try { + $fmt = new MessageFormatter(); +} +catch(IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; +} $fmt = msgfmt_create(); err($fmt); $fmt = MessageFormatter::create(); -err($fmt); -$fmt = new MessageFormatter('en'); -err($fmt); +err($fmt); +try { + $fmt = new MessageFormatter('en'); +} +catch(IntlException $ie) { + echo "IE: ".$ie->getMessage().PHP_EOL; +} $fmt = msgfmt_create('en'); err($fmt); $fmt = MessageFormatter::create('en'); err($fmt); foreach($args as $arg) { - $fmt = crt("O", $arg[0], $arg[1]); - err($fmt); - $fmt = crt("C", $arg[0], $arg[1]); - err($fmt); - $fmt = crt("P", $arg[0], $arg[1]); - err($fmt); + crt("O", $arg[0], $arg[1]); + crt("C", $arg[0], $arg[1]); + crt("P", $arg[0], $arg[1]); } ?> --EXPECTF-- -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d -'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' +IE: msgfmt_create: unable to parse input parameters Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' @@ -68,8 +80,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d -'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' +IE: msgfmt_create: unable to parse input parameters Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' diff --git a/ext/intl/tests/msgfmt_parse.phpt b/ext/intl/tests/msgfmt_parse.phpt index b9ec36374bcbd..2eaf630010399 100644 --- a/ext/intl/tests/msgfmt_parse.phpt +++ b/ext/intl/tests/msgfmt_parse.phpt @@ -36,9 +36,15 @@ function ut_main() foreach( $locales as $locale => $pattern ) { $str_res .= "\nLocale is: $locale\n"; - $fmt = ut_msgfmt_create( $locale, $pattern ); - if(!$fmt) { - $str_res .= dump(intl_get_error_message())."\n"; + try { + $fmt = ut_msgfmt_create( $locale, $pattern ); + if(!$fmt) { + $str_res .= dump(intl_get_error_message())."\n"; + continue; + } + } + catch (\IntlException $ie) { + $str_res .= "IE: ".$ie->getMessage().PHP_EOL; continue; } $str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n"; @@ -103,7 +109,7 @@ array ( ) Locale is: root -'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' +IE: msgfmt_create: message formatter creation failed Locale is: fr array ( diff --git a/ext/intl/tests/resourcebundle_create.phpt b/ext/intl/tests/resourcebundle_create.phpt index 2bf4f556a8609..99492a698b0b3 100644 --- a/ext/intl/tests/resourcebundle_create.phpt +++ b/ext/intl/tests/resourcebundle_create.phpt @@ -14,6 +14,7 @@ function ut_main() { $str_res .= debug( $r1 ); $str_res .= print_r( $r1['teststring'], true)."\n"; + // non-root one $r1 = ut_resourcebundle_create( 'es', BUNDLE ); $str_res .= debug( $r1 ); @@ -24,14 +25,22 @@ function ut_main() { $str_res .= debug( $r1 ); $str_res .= print_r( $r1['testsring'], true); - // fall out - $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false ); - $str_res .= debug( $r2 ); + try { + // fall out + $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false ); + } + catch (\IntlException $ie) { + $str_res .= "ie: ".$ie->getMessage().PHP_EOL; + } + + try { + // missing + $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' ); + } + catch (\IntlException $ie) { + $str_res .= "ie: ".$ie->getMessage().PHP_EOL; + } - // missing - $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' ); - $str_res .= debug( $r3 ); - return $str_res; } @@ -56,7 +65,5 @@ ResourceBundle Object ) -127: U_USING_DEFAULT_WARNING -NULL - 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR -NULL - 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR +ie: resourcebundle_ctor: Cannot load libICU resource bundle +ie: resourcebundle_ctor: Cannot load libICU resource bundle diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c index d8b030a6d14ee..7be1412b1328f 100644 --- a/ext/intl/transliterator/transliterator_methods.c +++ b/ext/intl/transliterator/transliterator_methods.c @@ -169,7 +169,7 @@ PHP_FUNCTION( transliterator_create_from_rules ) str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* (I'm not a big fan of non-obvious flow control macros ). * This one checks the error value, destroys object and returns false */ - INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed" ); + INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed", 0 ); /* Open ICU Transliterator. */ utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction, @@ -197,7 +197,7 @@ PHP_FUNCTION( transliterator_create_from_rules ) } transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ - INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed" ); + INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed", 0 ); } /* }}} */ @@ -228,10 +228,10 @@ PHP_FUNCTION( transliterator_create_inverse ) utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); INTL_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create " - "inverse ICU transliterator" ); + "inverse ICU transliterator", 0 ); transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ - INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed" ); + INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed", 0 ); } /* }}} */ From 0922eca0c7fd6864b4b631a48ff366ed10bc24ca Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 14:47:07 +0000 Subject: [PATCH 06/13] Made Phar throw exception on bad constructor. --- ext/phar/phar_object.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 0b173d1e0bb82..797681698868b 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1120,17 +1120,26 @@ PHP_METHOD(Phar, __construct) phar_archive_object *phar_obj; phar_archive_data *phar_data; zval *zobj = getThis(), arg1, arg2; + zend_error_handling zeh; + int rv; phar_obj = (phar_archive_object*)((char*)Z_OBJ_P(zobj) - Z_OBJ_P(zobj)->handlers->offset); is_data = instanceof_function(Z_OBJCE_P(zobj), phar_ce_data); if (is_data) { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) { + zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format); + zend_restore_error_handling(&zeh TSRMLS_CC); + if (rv == FAILURE) { return; } } else { - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) { + zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + if (rv == FAILURE) { + //Exception was thrown already return; } } @@ -4343,8 +4352,14 @@ PHP_METHOD(PharFileInfo, __construct) phar_entry_info *entry_info; phar_archive_data *phar_data; zval *zobj = getThis(), arg1; + zend_error_handling zeh; + int rv; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len) == FAILURE) { + zend_replace_error_handling(EH_THROW, phar_ce_PharException, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s", &fname, &fname_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == FAILURE) { return; } From 78ebf83ad3299bdb2617da60c9be68ce2cf33fb4 Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 14:54:49 +0000 Subject: [PATCH 07/13] Fixed fileinfo behaviour. --- ext/fileinfo/fileinfo.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index b4a556d57bcd5..33c67d1ec1dcc 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -301,8 +301,18 @@ PHP_FUNCTION(finfo_open) php_fileinfo *finfo; FILEINFO_DECLARE_INIT_OBJECT(object) char resolved_path[MAXPATHLEN]; + zend_error_handling zeh; + int rv; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) { + if (object) { + zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + } else { + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len); + } + + if (rv == FAILURE) { FILEINFO_DESTROY_OBJECT(object); RETURN_FALSE; } From d3267d0092a09eb3a0da2bd953ad21cf5bae325a Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 15:03:03 +0000 Subject: [PATCH 08/13] Fixed PDO constructor to not return null. --- ext/pdo/pdo_dbh.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index de9a6abbdc2e4..1796435c5fb02 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -208,9 +208,15 @@ static PHP_METHOD(PDO, dbh_constructor) zval *options = NULL; char alt_dsn[512]; int call_factory = 1; + zend_error_handling zeh; + int rv; - if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len, - &username, &usernamelen, &password, &passwordlen, &options)) { + zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len, + &username, &usernamelen, &password, &passwordlen, &options); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (FAILURE == rv) { ZEND_CTOR_MAKE_NULL(); return; } From 9803fccfbc1022e29dc89d04fcd3618ddf0c60ec Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 15:30:25 +0000 Subject: [PATCH 09/13] Made UConverter throw an exception if the constructor fails. --- ext/intl/converter/converter.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 9bba427409a9f..3b830bd440971 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -22,6 +22,7 @@ #include #include "../intl_error.h" +#include "../intl_common.h" typedef struct _php_converter_object { UConverter *src, *dest; @@ -556,11 +557,17 @@ static PHP_METHOD(UConverter, __construct) { size_t src_len = sizeof("utf-8") - 1; char *dest = src; size_t dest_len = src_len; + zend_error_handling zeh; + int rv; intl_error_reset(NULL); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", - &dest, &dest_len, &src, &src_len) == FAILURE) { + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", + &dest, &dest_len, &src, &src_len); + zend_restore_error_handling(&zeh TSRMLS_CC); + + if (rv == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "UConverter::__construct(): bad arguments", 0); return; From 6b232643e5c3b8f20a968e040b7c75695608a15b Mon Sep 17 00:00:00 2001 From: Danack Date: Sun, 15 Mar 2015 18:03:08 +0000 Subject: [PATCH 10/13] Reverted change to function name and added note of why it is different from the class it is actually changing. --- ext/pdo/pdo_stmt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index 947428789321f..ace865899e457 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -113,9 +113,9 @@ ZEND_END_ARG_INFO() RETURN_FALSE; \ } \ -static PHP_FUNCTION(dbrow_constructor) /* {{{ */ +//The class is called PDORow in userland, it is called PDOStatement in the manual. +static PHP_FUNCTION(dbstmt_constructor) /* {{{ */ { -// php_error_docref(NULL, E_ERROR, "You should not create a PDOStatement manually"); zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually"); } /* }}} */ @@ -2641,7 +2641,8 @@ static union _zend_function *row_get_ctor(zend_object *object) ctor.type = ZEND_INTERNAL_FUNCTION; ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0); ctor.scope = pdo_row_ce; - ctor.handler = ZEND_FN(dbrow_constructor); + //The class is called PDORow in userland, it is called PDOStatement in the manual. + ctor.handler = ZEND_FN(dbstmt_constructor); ctor.fn_flags = ZEND_ACC_PUBLIC; return (union _zend_function*)&ctor; From 910a3243063f0490a60e5c3c0e1467a6171f4e39 Mon Sep 17 00:00:00 2001 From: Danack Date: Mon, 16 Mar 2015 23:14:56 +0000 Subject: [PATCH 11/13] Fixed indentation. Fixed comment style. Fixed commented out code. --- ext/intl/converter/converter.c | 4 ++-- ext/intl/dateformat/dateformat_create.cpp | 4 ++-- ext/spl/spl_fixedarray.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 3b830bd440971..760d763b83dc6 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -563,9 +563,9 @@ static PHP_METHOD(UConverter, __construct) { intl_error_reset(NULL); zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", &dest, &dest_len, &src, &src_len); - zend_restore_error_handling(&zeh TSRMLS_CC); + zend_restore_error_handling(&zeh TSRMLS_CC); if (rv == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 9d6d5f4e97a38..31fcaeb7fcb90 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -79,8 +79,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { - // This is __construct being called on an instance - it is not - // a constructor. + /* This is __construct being called on an instance - it is not + a constructor. */ intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0); return; diff --git a/ext/spl/spl_fixedarray.c b/ext/spl/spl_fixedarray.c index dcac83d60df5c..9dbfa61344edd 100644 --- a/ext/spl/spl_fixedarray.c +++ b/ext/spl/spl_fixedarray.c @@ -564,11 +564,11 @@ SPL_METHOD(SplFixedArray, __construct) int rv; zend_error_handling zeh; -// zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC); -// rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size); -// zend_restore_error_handling(&zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &zeh TSRMLS_CC); + rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size); + zend_restore_error_handling(&zeh TSRMLS_CC); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &size) == FAILURE) { + if (rv == FAILURE) { return; } From 1018f462d8bb0a12b238d9d11c141038beaf2a6c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 30 Mar 2015 18:53:38 +0300 Subject: [PATCH 12/13] Patch improvement: Removed the corresponding core code. Fixed ext/com_dotnet and ext/date. Refactored ext/intl changes. Improved ext/fileinfo and ext/pdo changes. Fixed tests. --- Zend/zend_API.c | 9 --- Zend/zend_API.h | 6 -- Zend/zend_vm_def.h | 7 -- Zend/zend_vm_execute.h | 38 --------- ext/com_dotnet/com_com.c | 2 - ext/com_dotnet/com_dotnet.c | 3 - ext/date/php_date.c | 10 +-- ext/fileinfo/fileinfo.c | 55 +++++++------ ext/fileinfo/tests/bug61173.phpt | 7 +- ext/fileinfo/tests/finfo_open_error.phpt | 8 +- .../breakiterator/breakiterator_methods.cpp | 4 +- .../rulebasedbreakiterator_methods.cpp | 11 ++- .../calendar/gregoriancalendar_methods.cpp | 51 ++++++------ ext/intl/collator/collator_create.c | 22 +++--- ext/intl/converter/converter.c | 6 +- ext/intl/dateformat/dateformat_create.cpp | 31 ++++---- ext/intl/formatter/formatter_main.c | 24 +++--- ext/intl/intl_data.h | 4 +- ext/intl/intl_error.c | 55 ++----------- ext/intl/intl_error.h | 6 -- ext/intl/msgformat/msgformat.c | 26 ++++--- ext/intl/msgformat/msgformat_class.c | 4 +- .../resourcebundle/resourcebundle_class.c | 25 +++--- ext/intl/spoofchecker/spoofchecker_create.c | 7 +- .../tests/breakiter___construct_error.phpt | 56 +++++++------ ext/intl/tests/bug62017.phpt | 12 +-- ext/intl/tests/bug62081.phpt | 7 +- .../dateformat___construct_bad_tz_cal.phpt | 35 +++++---- .../tests/dateformat_calendars_variant2.phpt | 7 +- ext/intl/tests/formatter_fail.phpt | 71 ++++++++++------- ext/intl/tests/formatter_format.phpt | 9 +-- .../gregoriancalendar___construct_error.phpt | 26 +++---- ext/intl/tests/msgfmt_fail.phpt | 78 ++++++++++++------- ext/intl/tests/msgfmt_fail2.phpt | 43 ++++++++-- ext/intl/tests/msgfmt_parse.phpt | 14 +--- ext/intl/tests/resourcebundle_create.phpt | 29 +++---- ext/intl/tests/ut_common.inc | 20 ++++- .../transliterator/transliterator_methods.c | 8 +- ext/pdo/pdo_dbh.c | 34 ++++---- ext/pdo/pdo_stmt.c | 6 +- ext/pdo/tests/pdo_036.phpt | 37 ++++----- ext/pdo/tests/pdorow.phpt | 22 ++---- .../tests/pdo_mysql___construct.phpt | 7 +- .../tests/pdo_mysql___construct_options.phpt | 7 +- .../tests/pdo_mysql___construct_uri.phpt | 3 - ext/phar/phar_object.c | 2 +- ext/phar/tests/badparameters.phpt | 31 ++++++-- ext/phar/tests/bug60261.phpt | 8 +- ext/phar/tests/pharfileinfo_construct.phpt | 10 +-- ext/reflection/php_reflection.c | 2 +- 50 files changed, 504 insertions(+), 501 deletions(-) diff --git a/Zend/zend_API.c b/Zend/zend_API.c index e6f94798d088d..4295159c7b01b 100644 --- a/Zend/zend_API.c +++ b/Zend/zend_API.c @@ -4128,15 +4128,6 @@ ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_functi } /* }}} */ -ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data) /* {{{ */ -{ - if (EX(return_value)) { - Z_OBJ_P(EX(return_value)) = NULL; - ZVAL_NULL(EX(return_value)); - } -} -/* }}} */ - ZEND_API const char *zend_get_object_type(const zend_class_entry *ce) /* {{{ */ { if(ce->ce_flags & ZEND_ACC_TRAIT) { diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 694c818f6034f..b70dd26ef8c22 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -538,8 +538,6 @@ ZEND_API int zend_set_local_var_str(const char *name, size_t len, zval *value, i ZEND_API zend_string *zend_find_alias_name(zend_class_entry *ce, zend_string *name); ZEND_API zend_string *zend_resolve_method_name(zend_class_entry *ce, zend_function *f); -ZEND_API void zend_ctor_make_null(zend_execute_data *execute_data); - ZEND_API const char *zend_get_object_type(const zend_class_entry *ce); #define add_method(arg, key, method) add_assoc_function((arg), (key), (method)) @@ -651,10 +649,6 @@ END_EXTERN_C() } \ } while (0) -/* May be used in internal constructors to make them return NULL */ -#define ZEND_CTOR_MAKE_NULL() \ - zend_ctor_make_null(execute_data) - #define RETURN_ZVAL_FAST(z) { RETVAL_ZVAL_FAST(z); return; } #define HASH_OF(p) (Z_TYPE_P(p)==IS_ARRAY ? Z_ARRVAL_P(p) : ((Z_TYPE_P(p)==IS_OBJECT ? Z_OBJ_HT_P(p)->get_properties((p)) : NULL))) diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h index 8c1f1b4a8f0e5..7dcad6c379f7a 100644 --- a/Zend/zend_vm_def.h +++ b/Zend/zend_vm_def.h @@ -2950,10 +2950,6 @@ ZEND_VM_HANDLER(113, ZEND_INIT_STATIC_METHOD_CALL, CONST|VAR, CONST|TMPVAR|UNUSE EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (OP2_TYPE == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -4704,9 +4700,6 @@ ZEND_VM_HANDLER(68, ZEND_NEW, CONST|VAR, ANY) if (EXPECTED(RETURN_VALUE_USED(opline))) { ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); - EX(call)->return_value = EX_VAR(opline->result.var); - } else { - EX(call)->return_value = NULL; } CHECK_EXCEPTION(); diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h index 31ee053ef455c..c628928cd40a2 100644 --- a/Zend/zend_vm_execute.h +++ b/Zend/zend_vm_execute.h @@ -3100,9 +3100,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_CONST_HANDLER(ZEND_OP if (EXPECTED(RETURN_VALUE_USED(opline))) { ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); - EX(call)->return_value = EX_VAR(opline->result.var); - } else { - EX(call)->return_value = NULL; } CHECK_EXCEPTION(); @@ -5082,10 +5079,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_CONST == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -6984,10 +6977,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_UNUSED == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -8466,10 +8455,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_CV == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -10015,10 +10000,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_C EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -13795,9 +13776,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_NEW_SPEC_VAR_HANDLER(ZEND_OPCO if (EXPECTED(RETURN_VALUE_USED(opline))) { ZVAL_COPY(EX_VAR(opline->result.var), &object_zval); - EX(call)->return_value = EX_VAR(opline->result.var); - } else { - EX(call)->return_value = NULL; } CHECK_EXCEPTION(); @@ -15880,10 +15858,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_CONST == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -17455,10 +17429,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_UNUSED == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -19072,10 +19042,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if (IS_CV == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } @@ -20631,10 +20597,6 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_INIT_STATIC_METHOD_CALL_SPEC_V EX(call) = zend_vm_stack_push_call_frame(ZEND_CALL_NESTED_FUNCTION, fbc, opline->extended_value, ce, object, EX(call)); - if ((IS_TMP_VAR|IS_VAR) == IS_UNUSED) { - EX(call)->return_value = NULL; - } - CHECK_EXCEPTION(); ZEND_VM_NEXT_OPCODE(); } diff --git a/ext/com_dotnet/com_com.c b/ext/com_dotnet/com_com.c index d61d933e7a798..80ef70e7e01f4 100644 --- a/ext/com_dotnet/com_com.c +++ b/ext/com_dotnet/com_com.c @@ -66,7 +66,6 @@ PHP_FUNCTION(com_create_instance) &typelib_name, &typelib_name_len)) { php_com_throw_exception(E_INVALIDARG, "Could not create COM object - invalid arguments!"); - ZEND_CTOR_MAKE_NULL(); return; } @@ -230,7 +229,6 @@ PHP_FUNCTION(com_create_instance) php_com_throw_exception(res, msg); efree(msg); - ZEND_CTOR_MAKE_NULL(); return; } diff --git a/ext/com_dotnet/com_dotnet.c b/ext/com_dotnet/com_dotnet.c index 974876a8538c3..7e0124b062280 100644 --- a/ext/com_dotnet/com_dotnet.c +++ b/ext/com_dotnet/com_dotnet.c @@ -208,7 +208,6 @@ PHP_FUNCTION(com_dotnet_create_instance) if (err) LocalFree(err); php_com_throw_exception(hr, buf); - ZEND_CTOR_MAKE_NULL(); return; } stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff); @@ -248,7 +247,6 @@ PHP_FUNCTION(com_dotnet_create_instance) &datatype_name, &datatype_name_len, &obj->code_page)) { php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!"); - ZEND_CTOR_MAKE_NULL(); return; } @@ -314,7 +312,6 @@ PHP_FUNCTION(com_dotnet_create_instance) LocalFree(err); } php_com_throw_exception(hr, buf); - ZEND_CTOR_MAKE_NULL(); return; } } diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 94d3a19bcd799..0021483de1181 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -2670,9 +2670,7 @@ PHP_METHOD(DateTime, __construct) zend_replace_error_handling(EH_THROW, NULL, &error_handling); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|sO!", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) { - if (!php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1)) { - ZEND_CTOR_MAKE_NULL(); - } + php_date_initialize(Z_PHPDATE_P(getThis()), time_str, time_str_len, NULL, timezone_object, 1); } zend_restore_error_handling(&error_handling); } @@ -3679,9 +3677,7 @@ PHP_METHOD(DateTimeZone, __construct) zend_replace_error_handling(EH_THROW, NULL, &error_handling); if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s", &tz, &tz_len)) { tzobj = Z_PHPTIMEZONE_P(getThis()); - if (FAILURE == timezone_initialize(tzobj, tz)) { - ZEND_CTOR_MAKE_NULL(); - } + timezone_initialize(tzobj, tz); } zend_restore_error_handling(&error_handling); } @@ -4113,8 +4109,6 @@ PHP_METHOD(DateInterval, __construct) diobj = Z_PHPINTERVAL_P(getThis()); diobj->diff = reltime; diobj->initialized = 1; - } else { - ZEND_CTOR_MAKE_NULL(); } } zend_restore_error_handling(&error_handling); diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 33c67d1ec1dcc..075397105bd2d 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -282,15 +282,6 @@ PHP_MINFO_FUNCTION(fileinfo) } /* }}} */ -#define FILEINFO_DESTROY_OBJECT(object) \ - do { \ - if (object) { \ - zend_object_store_ctor_failed(Z_OBJ_P(object)); \ - Z_OBJ_P(object) = NULL; \ - ZEND_CTOR_MAKE_NULL(); \ - } \ - } while (0) - /* {{{ proto resource finfo_open([int options [, string arg]]) Create a new fileinfo resource. */ PHP_FUNCTION(finfo_open) @@ -302,18 +293,17 @@ PHP_FUNCTION(finfo_open) FILEINFO_DECLARE_INIT_OBJECT(object) char resolved_path[MAXPATHLEN]; zend_error_handling zeh; - int rv; if (object) { - zend_replace_error_handling(EH_THROW, NULL, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len); - zend_restore_error_handling(&zeh TSRMLS_CC); - } else { - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len); + zend_replace_error_handling(EH_THROW, NULL, &zeh); } - - if (rv == FAILURE) { - FILEINFO_DESTROY_OBJECT(object); + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lp", &options, &file, &file_len) == FAILURE) { + if (object) { + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(NULL, "Constructor failed", 0); + } + } RETURN_FALSE; } @@ -332,11 +322,21 @@ PHP_FUNCTION(finfo_open) } else if (file && *file) { /* user specified file, perform open_basedir checks */ if (php_check_open_basedir(file)) { - FILEINFO_DESTROY_OBJECT(object); + if (object) { + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(NULL, "Constructor failed", 0); + } + } RETURN_FALSE; } if (!expand_filepath_with_mode(file, resolved_path, NULL, 0, CWD_EXPAND)) { - FILEINFO_DESTROY_OBJECT(object); + if (object) { + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(NULL, "Constructor failed", 0); + } + } RETURN_FALSE; } file = resolved_path; @@ -350,7 +350,12 @@ PHP_FUNCTION(finfo_open) if (finfo->magic == NULL) { efree(finfo); php_error_docref(NULL, E_WARNING, "Invalid mode '%pd'.", options); - FILEINFO_DESTROY_OBJECT(object); + if (object) { + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(NULL, "Constructor failed", 0); + } + } RETURN_FALSE; } @@ -358,11 +363,17 @@ PHP_FUNCTION(finfo_open) php_error_docref(NULL, E_WARNING, "Failed to load magic database at '%s'.", file); magic_close(finfo->magic); efree(finfo); - FILEINFO_DESTROY_OBJECT(object); + if (object) { + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(NULL, "Constructor failed", 0); + } + } RETURN_FALSE; } if (object) { + zend_restore_error_handling(&zeh); FILEINFO_REGISTER_OBJECT(object, finfo); } else { RETURN_RES(zend_register_resource(finfo, le_fileinfo)); diff --git a/ext/fileinfo/tests/bug61173.phpt b/ext/fileinfo/tests/bug61173.phpt index 521176fe76925..838faf5b7d302 100644 --- a/ext/fileinfo/tests/bug61173.phpt +++ b/ext/fileinfo/tests/bug61173.phpt @@ -10,5 +10,8 @@ if (!class_exists('finfo')) $finfo = new finfo(1, '', false); var_dump($finfo); --EXPECTF-- -Warning: finfo::finfo() expects at most 2 parameters, 3 given in %s on line %d -NULL +Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects at most 2 parameters, 3 given' in %sbug61173.php:3 +Stack trace: +#0 %sbug61173.php(3): finfo->finfo(1, '', false) +#1 {main} + thrown in %sbug61173.php on line 3 diff --git a/ext/fileinfo/tests/finfo_open_error.phpt b/ext/fileinfo/tests/finfo_open_error.phpt index ed43a8b4536e8..d02be60e3191c 100644 --- a/ext/fileinfo/tests/finfo_open_error.phpt +++ b/ext/fileinfo/tests/finfo_open_error.phpt @@ -46,6 +46,8 @@ resource(6) of type (file_info) Warning: finfo_open() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 16 bool(false) -Warning: finfo::finfo() expects parameter 1 to be integer, string given in %sfinfo_open_error.php on line 18 -NULL -===DONE=== +Fatal error: Uncaught exception 'Exception' with message 'finfo::finfo() expects parameter 1 to be integer, string given' in %sfinfo_open_error.php:18 +Stack trace: +#0 %sfinfo_open_error.php(18): finfo->finfo('foobar') +#1 {main} + thrown in %sfinfo_open_error.php on line 18 diff --git a/ext/intl/breakiterator/breakiterator_methods.cpp b/ext/intl/breakiterator/breakiterator_methods.cpp index 02d228653a61c..baab5a682d68e 100644 --- a/ext/intl/breakiterator/breakiterator_methods.cpp +++ b/ext/intl/breakiterator/breakiterator_methods.cpp @@ -162,12 +162,12 @@ U_CFUNC PHP_FUNCTION(breakiter_set_text) BREAKITER_METHOD_FETCH_OBJECT; ut = utext_openUTF8(ut, text->val, text->len, BREAKITER_ERROR_CODE_P(bio)); - INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText", 0); + INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error opening UText"); bio->biter->setText(ut, BREAKITER_ERROR_CODE(bio)); utext_close(ut); /* ICU shallow clones the UText */ INTL_CTOR_CHECK_STATUS(bio, "breakiter_set_text: error calling " - "BreakIterator::setText()", 0); + "BreakIterator::setText()"); /* When ICU clones the UText, it does not copy the buffer, so we have to * keep the string buffer around by holding a reference to its zval. This diff --git a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp index c1121341242eb..b43f8212d0ed9 100644 --- a/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp +++ b/ext/intl/breakiterator/rulebasedbreakiterator_methods.cpp @@ -24,6 +24,7 @@ extern "C" { } #include "../intl_convertcpp.h" +#include "../intl_common.h" static inline RuleBasedBreakIterator *fetch_rbbi(BreakIterator_object *bio) { return (RuleBasedBreakIterator*)bio->biter; @@ -97,15 +98,17 @@ static void _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAMETERS) U_CFUNC PHP_METHOD(IntlRuleBasedBreakIterator, __construct) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); _php_intlrbbi_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); - if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } U_CFUNC PHP_FUNCTION(rbbi_get_rules) diff --git a/ext/intl/calendar/gregoriancalendar_methods.cpp b/ext/intl/calendar/gregoriancalendar_methods.cpp index 69bae08e062bc..d9572a0668c02 100644 --- a/ext/intl/calendar/gregoriancalendar_methods.cpp +++ b/ext/intl/calendar/gregoriancalendar_methods.cpp @@ -25,18 +25,20 @@ #include extern "C" { #include "../php_intl.h" +#include "../intl_common.h" #define USE_TIMEZONE_POINTER 1 #include "../timezone/timezone_class.h" #define USE_CALENDAR_POINTER 1 #include "calendar_class.h" #include +#include "zend_exceptions.h" } static inline GregorianCalendar *fetch_greg(Calendar_object *co) { return (GregorianCalendar*)co->ucal; } -static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS) { zval *tz_object = NULL; zval args_a[6] = {0}, @@ -51,8 +53,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend // parameter number validation / variant determination if (ZEND_NUM_ARGS() > 6 || zend_get_parameters_array_ex(ZEND_NUM_ARGS(), args) == FAILURE) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: too many arguments", 0, is_constructor); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: too many arguments", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -60,9 +62,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend variant > 0 && Z_TYPE(args[variant - 1]) == IS_NULL; variant--) {} if (variant == 4) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: no variant with 4 arguments " - "(excluding trailing NULLs)", 0, is_constructor); + "(excluding trailing NULLs)", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -71,8 +73,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend if (variant <= 2) { if (zend_parse_parameters(MIN(ZEND_NUM_ARGS(), 2), "|z!s!", &tz_object, &locale, &locale_len) == FAILURE) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: bad arguments", 0, is_constructor); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -80,8 +82,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend if (variant > 2 && zend_parse_parameters(ZEND_NUM_ARGS(), "lll|lll", &largs[0], &largs[1], &largs[2], &largs[3], &largs[4], &largs[5]) == FAILURE) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, - "intlgregcal_create_instance: bad arguments", 0, is_constructor); + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, + "intlgregcal_create_instance: bad arguments", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -104,8 +106,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend gcal = new GregorianCalendar(tz, Locale::createFromName(locale), status); if (U_FAILURE(status)) { - intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " - "creating ICU GregorianCalendar from time zone and locale", 0, is_constructor); + intl_error_set(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from time zone and locale", 0); if (gcal) { delete gcal; } @@ -117,9 +119,9 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend // From date/time (3, 5 or 6 arguments) for (int i = 0; i < variant; i++) { if (largs[i] < INT32_MIN || largs[i] > INT32_MAX) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: at least one of the arguments" - " has an absolute value that is too large", 0, is_constructor); + " has an absolute value that is too large", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -137,8 +139,8 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend status); } if (U_FAILURE(status)) { - intl_error_set_ex(NULL, status, "intlgregcal_create_instance: error " - "creating ICU GregorianCalendar from date", 0, is_constructor); + intl_error_set(NULL, status, "intlgregcal_create_instance: error " + "creating ICU GregorianCalendar from date", 0); if (gcal) { delete gcal; } @@ -154,10 +156,10 @@ static void _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAMETERS, zend strlen(tzinfo->name), US_INV); #endif if (tzstr.isBogus()) { - intl_error_set_ex(NULL, U_ILLEGAL_ARGUMENT_ERROR, + intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "intlgregcal_create_instance: could not create UTF-8 string " "from PHP's default timezone name (see date_default_timezone_get())", - 0, is_constructor); + 0); delete gcal; Z_OBJ_P(return_value) = NULL; return; @@ -179,7 +181,7 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) object_init_ex(return_value, GregorianCalendar_ce_ptr); ZVAL_COPY_VALUE(&orig, return_value); - _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { zval_dtor(&orig); @@ -189,17 +191,18 @@ U_CFUNC PHP_FUNCTION(intlgregcal_create_instance) U_CFUNC PHP_METHOD(IntlGregorianCalendar, __construct) { - zval orig_this = *getThis(); - intl_error_reset(NULL); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); //changes this to IS_NULL (without first destroying) if there's an error - _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + _php_intlgregcal_constructor_body(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } U_CFUNC PHP_FUNCTION(intlgregcal_set_gregorian_change) diff --git a/ext/intl/collator/collator_create.c b/ext/intl/collator/collator_create.c index 7631d76ff426e..c6bc3fd209262 100644 --- a/ext/intl/collator/collator_create.c +++ b/ext/intl/collator/collator_create.c @@ -25,7 +25,7 @@ #include "intl_data.h" /* {{{ */ -static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; size_t locale_len = 0; @@ -38,8 +38,8 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor if( zend_parse_parameters( ZEND_NUM_ARGS(), "s", &locale, &locale_len ) == FAILURE ) { - intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "collator_create: unable to parse input params", 0, is_constructor ); + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "collator_create: unable to parse input params", 0 ); zval_dtor(return_value); RETURN_NULL(); } @@ -53,7 +53,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor /* Open ICU collator. */ co->ucoll = ucol_open( locale, COLLATOR_ERROR_CODE_P( co ) ); - INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator", is_constructor); + INTL_CTOR_CHECK_STATUS(co, "collator_create: unable to open ICU collator"); } /* }}} */ @@ -63,7 +63,7 @@ static void collator_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor PHP_FUNCTION( collator_create ) { object_init_ex( return_value, Collator_ce_ptr ); - collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); } /* }}} */ @@ -72,15 +72,17 @@ PHP_FUNCTION( collator_create ) */ PHP_METHOD( Collator, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); - collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + collator_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/converter/converter.c b/ext/intl/converter/converter.c index 760d763b83dc6..fd3aced34db97 100644 --- a/ext/intl/converter/converter.c +++ b/ext/intl/converter/converter.c @@ -562,10 +562,10 @@ static PHP_METHOD(UConverter, __construct) { intl_error_reset(NULL); - zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh TSRMLS_CC); + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &zeh); rv = zend_parse_parameters(ZEND_NUM_ARGS(), "|s!s!", - &dest, &dest_len, &src, &src_len); - zend_restore_error_handling(&zeh TSRMLS_CC); + &dest, &dest_len, &src, &src_len); + zend_restore_error_handling(&zeh); if (rv == FAILURE) { intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, diff --git a/ext/intl/dateformat/dateformat_create.cpp b/ext/intl/dateformat/dateformat_create.cpp index 31fcaeb7fcb90..b7ad7b5126451 100644 --- a/ext/intl/dateformat/dateformat_create.cpp +++ b/ext/intl/dateformat/dateformat_create.cpp @@ -34,9 +34,10 @@ extern "C" { } #include "dateformat_helpers.h" +#include "zend_exceptions.h" /* {{{ */ -static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { zval *object; @@ -64,8 +65,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) if (zend_parse_parameters(ZEND_NUM_ARGS(), "sll|zzs", &locale_str, &locale_len, &date_type, &time_type, &timezone_zv, &calendar_zv, &pattern_str, &pattern_str_len) == FAILURE) { - intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " - "unable to parse input parameters", 0, is_constructor); + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: " + "unable to parse input parameters", 0); Z_OBJ_P(return_value) = NULL; return; } @@ -79,8 +80,6 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) DATE_FORMAT_METHOD_FETCH_OBJECT_NO_CHECK; if (DATE_FORMAT_OBJECT(dfo) != NULL) { - /* This is __construct being called on an instance - it is not - a constructor. */ intl_errors_set(INTL_DATA_ERROR_P(dfo), U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: cannot call constructor twice", 0); return; @@ -112,8 +111,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) pattern_str, pattern_str_len, &INTL_DATA_ERROR_CODE(dfo)); if (U_FAILURE(INTL_DATA_ERROR_CODE(dfo))) { /* object construction -> only set global error */ - intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " - "error converting pattern to UTF-16", 0, is_constructor); + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: " + "error converting pattern to UTF-16", 0); goto error; } } @@ -141,8 +140,8 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) df->adoptTimeZone(timezone); } } else { - intl_error_set_ex(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " - "formatter creation failed", 0, is_constructor); + intl_error_set(NULL, INTL_DATA_ERROR_CODE(dfo), "datefmt_create: date " + "formatter creation failed", 0); goto error; } @@ -177,7 +176,7 @@ static void datefmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) U_CFUNC PHP_FUNCTION( datefmt_create ) { object_init_ex( return_value, IntlDateFormatter_ce_ptr ); - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -189,16 +188,18 @@ U_CFUNC PHP_FUNCTION( datefmt_create ) */ U_CFUNC PHP_METHOD( IntlDateFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); /* return_value param is being changed, therefore we will always return * NULL here */ return_value = getThis(); - datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + datefmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/formatter/formatter_main.c b/ext/intl/formatter/formatter_main.c index c8ca65da272f2..5d5a139688a52 100644 --- a/ext/intl/formatter/formatter_main.c +++ b/ext/intl/formatter/formatter_main.c @@ -25,7 +25,7 @@ #include "intl_convert.h" /* {{{ */ -static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; char* pattern = NULL; @@ -39,8 +39,8 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) if( zend_parse_parameters( ZEND_NUM_ARGS(), "sl|s", &locale, &locale_len, &style, &pattern, &pattern_len ) == FAILURE ) { - intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "numfmt_create: unable to parse input parameters", 0, is_constructor ); + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "numfmt_create: unable to parse input parameters", 0 ); Z_OBJ_P(return_value) = NULL; return; } @@ -52,7 +52,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(nfo)); - INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16", is_constructor); + INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: error converting pattern to UTF-16"); } if(locale_len == 0) { @@ -66,7 +66,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) efree(spattern); } - INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed", is_constructor); + INTL_CTOR_CHECK_STATUS(nfo, "numfmt_create: number formatter creation failed"); } /* }}} */ @@ -78,7 +78,7 @@ static void numfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) PHP_FUNCTION( numfmt_create ) { object_init_ex( return_value, NumberFormatter_ce_ptr ); - numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -90,15 +90,17 @@ PHP_FUNCTION( numfmt_create ) */ PHP_METHOD( NumberFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); - numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + numfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/intl_data.h b/ext/intl/intl_data.h index c49214ffcd622..6001aa128513c 100644 --- a/ext/intl/intl_data.h +++ b/ext/intl/intl_data.h @@ -64,11 +64,11 @@ typedef struct _intl_data { } /* Check status, if error - destroy value and exit */ -#define INTL_CTOR_CHECK_STATUS(obj, msg, forceException) \ +#define INTL_CTOR_CHECK_STATUS(obj, msg) \ intl_error_set_code( NULL, INTL_DATA_ERROR_CODE((obj)) ); \ if( U_FAILURE( INTL_DATA_ERROR_CODE((obj)) ) ) \ { \ - intl_errors_set_custom_msg_ex( INTL_DATA_ERROR_P((obj)), msg, 0, forceException ); \ + intl_errors_set_custom_msg( INTL_DATA_ERROR_P((obj)), msg, 0 ); \ /* yes, this is ugly, but it alreay is */ \ if (return_value != getThis()) { \ zval_dtor(return_value); \ diff --git a/ext/intl/intl_error.c b/ext/intl/intl_error.c index 8ea5e7b4cf129..a946705a764c5 100644 --- a/ext/intl/intl_error.c +++ b/ext/intl/intl_error.c @@ -102,26 +102,15 @@ void intl_error_reset( intl_error* err ) * Set last error message to msg copying it if needed. */ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) -{ - intl_error_set_custom_msg_ex( err, msg, copyMsg, 0 ); -} -/* }}} */ - - -/* {{{ void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ) - * Set last error message to msg copying it if needed. - */ -void intl_error_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if( !msg ) return; if( !err ) { - if ( forceException || INTL_G( use_exceptions ) ) { - zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg ); - } else if( INTL_G( error_level ) ) { + if( INTL_G( error_level ) ) php_error_docref( NULL, INTL_G( error_level ), "%s", msg ); - } + if( INTL_G( use_exceptions ) ) + zend_throw_exception_ex( IntlException_ce_ptr, 0, "%s", msg ); } if( !err && !( err = intl_g_error_get( ) ) ) return; @@ -192,39 +181,19 @@ UErrorCode intl_error_get_code( intl_error* err ) * Set error code and message. */ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) -{ - intl_error_set_ex( err, code, msg, copyMsg, 0 ); -} -/* }}} */ - - -/* {{{ void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) - * Set error code and message. - */ -void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_error_set_code( err, code ); - intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); + intl_error_set_custom_msg( err, msg, copyMsg ); } /* }}} */ - /* {{{ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) * Set error code and message. */ void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ) -{ - intl_errors_set_ex( err, code, msg, copyMsg, 0 ); -} -/* }}} */ - -/* {{{ void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg ) - * Set error code and message. - */ -void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ) { intl_errors_set_code( err, code ); - intl_errors_set_custom_msg_ex( err, msg, copyMsg, forceException ); + intl_errors_set_custom_msg( err, msg, copyMsg ); } /* }}} */ @@ -242,24 +211,14 @@ void intl_errors_reset( intl_error* err ) /* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) */ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) -{ - intl_errors_set_custom_msg_ex( err, msg, copyMsg, 0 ); -} -/* }}} */ - - -/* {{{ void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ) - */ -void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ) { if(err) { - intl_error_set_custom_msg_ex( err, msg, copyMsg, forceException ); + intl_error_set_custom_msg( err, msg, copyMsg ); } - intl_error_set_custom_msg_ex( NULL, msg, copyMsg, forceException ); + intl_error_set_custom_msg( NULL, msg, copyMsg ); } /* }}} */ - /* {{{ intl_errors_set_code( intl_error* err, UErrorCode err_code ) */ void intl_errors_set_code( intl_error* err, UErrorCode err_code ) diff --git a/ext/intl/intl_error.h b/ext/intl/intl_error.h index 4c9349b281493..02d62f0299666 100644 --- a/ext/intl/intl_error.h +++ b/ext/intl/intl_error.h @@ -36,21 +36,15 @@ void intl_error_init( intl_error* err ); void intl_error_reset( intl_error* err ); void intl_error_set_code( intl_error* err, UErrorCode err_code ); void intl_error_set_custom_msg( intl_error* err, char* msg, int copyMsg ); -void intl_error_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ); void intl_error_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ); -void intl_error_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ); - - UErrorCode intl_error_get_code( intl_error* err ); zend_string* intl_error_get_message( intl_error* err ); // Wrappers to synchonize object's and global error structures. void intl_errors_reset( intl_error* err ); void intl_errors_set_custom_msg( intl_error* err, char* msg, int copyMsg ); -void intl_errors_set_custom_msg_ex( intl_error* err, char* msg, int copyMsg, int forceException ); void intl_errors_set_code( intl_error* err, UErrorCode err_code ); void intl_errors_set( intl_error* err, UErrorCode code, char* msg, int copyMsg ); -void intl_errors_set_ex( intl_error* err, UErrorCode code, char* msg, int copyMsg, int forceException ); // Other error helpers smart_str intl_parse_error_to_string( UParseError* pe ); diff --git a/ext/intl/msgformat/msgformat.c b/ext/intl/msgformat/msgformat.c index 34923f92a5cc9..15d6ef8321425 100644 --- a/ext/intl/msgformat/msgformat.c +++ b/ext/intl/msgformat/msgformat.c @@ -26,7 +26,7 @@ #include "intl_convert.h" /* {{{ */ -static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char* locale; char* pattern; @@ -42,8 +42,8 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) if( zend_parse_parameters( ZEND_NUM_ARGS(), "ss", &locale, &locale_len, &pattern, &pattern_len ) == FAILURE ) { - intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "msgfmt_create: unable to parse input parameters", 0, is_constructor ); + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "msgfmt_create: unable to parse input parameters", 0 ); Z_OBJ_P(return_value) = NULL; return; } @@ -54,7 +54,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) /* Convert pattern (if specified) to UTF-16. */ if(pattern && pattern_len) { intl_convert_utf8_to_utf16(&spattern, &spattern_len, pattern, pattern_len, &INTL_DATA_ERROR_CODE(mfo)); - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16", is_constructor); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to UTF-16"); } else { spattern_len = 0; spattern = NULL; @@ -66,7 +66,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) #ifdef MSG_FORMAT_QUOTE_APOS if(msgformat_fix_quotes(&spattern, &spattern_len, &INTL_DATA_ERROR_CODE(mfo)) != SUCCESS) { - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format", is_constructor); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: error converting pattern to quote-friendly format"); } #endif @@ -84,7 +84,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) efree(spattern); } - INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed", is_constructor); + INTL_CTOR_CHECK_STATUS(mfo, "msgfmt_create: message formatter creation failed"); } /* }}} */ @@ -96,7 +96,7 @@ static void msgfmt_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) PHP_FUNCTION( msgfmt_create ) { object_init_ex( return_value, MessageFormatter_ce_ptr ); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } @@ -108,15 +108,17 @@ PHP_FUNCTION( msgfmt_create ) */ PHP_METHOD( MessageFormatter, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); - msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + msgfmt_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/msgformat/msgformat_class.c b/ext/intl/msgformat/msgformat_class.c index 1296d087e1e38..8d464c6ca48d6 100644 --- a/ext/intl/msgformat/msgformat_class.c +++ b/ext/intl/msgformat/msgformat_class.c @@ -87,10 +87,10 @@ zend_object *MessageFormatter_object_clone(zval *object) if (U_FAILURE(INTL_DATA_ERROR_CODE(mfo))) { intl_errors_set(INTL_DATA_ERROR_P(mfo), INTL_DATA_ERROR_CODE(mfo), "Failed to clone MessageFormatter object", 0); - zend_throw_exception_ex(IntlException_ce_ptr, 0, "Failed to clone MessageFormatter object"); + zend_throw_exception_ex(NULL, 0, "Failed to clone MessageFormatter object"); } } else { - zend_throw_exception_ex(IntlException_ce_ptr, 0, "Cannot clone unconstructed MessageFormatter"); + zend_throw_exception_ex(NULL, 0, "Cannot clone unconstructed MessageFormatter"); } return new_obj; } diff --git a/ext/intl/resourcebundle/resourcebundle_class.c b/ext/intl/resourcebundle/resourcebundle_class.c index 60800fe1a99ee..d8d1aa0d9c5d8 100644 --- a/ext/intl/resourcebundle/resourcebundle_class.c +++ b/ext/intl/resourcebundle/resourcebundle_class.c @@ -25,6 +25,7 @@ #include "php_intl.h" #include "intl_data.h" +#include "intl_common.h" #include "resourcebundle/resourcebundle.h" #include "resourcebundle/resourcebundle_iterator.h" @@ -74,7 +75,7 @@ static zend_object *ResourceBundle_object_create( zend_class_entry *ce ) /* }}} */ /* {{{ ResourceBundle_ctor */ -static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constructor) +static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS) { const char *bundlename; size_t bundlename_len = 0; @@ -90,8 +91,8 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const if( zend_parse_parameters( ZEND_NUM_ARGS(), "s!s!|b", &locale, &locale_len, &bundlename, &bundlename_len, &fallback ) == FAILURE ) { - intl_error_set_ex( NULL, U_ILLEGAL_ARGUMENT_ERROR, - "resourcebundle_ctor: unable to parse input parameters", 0, is_constructor ); + intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, + "resourcebundle_ctor: unable to parse input parameters", 0 ); Z_OBJ_P(return_value) = NULL; return; } @@ -108,7 +109,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const rb->me = ures_openDirect(bundlename, locale, &INTL_DATA_ERROR_CODE(rb)); } - INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle", is_constructor); + INTL_CTOR_CHECK_STATUS(rb, "resourcebundle_ctor: Cannot load libICU resource bundle"); if (!fallback && (INTL_DATA_ERROR_CODE(rb) == U_USING_FALLBACK_WARNING || INTL_DATA_ERROR_CODE(rb) == U_USING_DEFAULT_WARNING)) { @@ -119,7 +120,7 @@ static void resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_const bundlename ? bundlename : "(default data)", locale, ures_getLocaleByType( rb->me, ULOC_ACTUAL_LOCALE, &INTL_DATA_ERROR_CODE(rb))); - intl_errors_set_custom_msg_ex(INTL_DATA_ERROR_P(rb), pbuf, 1, is_constructor); + intl_errors_set_custom_msg(INTL_DATA_ERROR_P(rb), pbuf, 1); efree(pbuf); Z_OBJ_P(return_value) = NULL; } @@ -139,15 +140,17 @@ ZEND_END_ARG_INFO() */ PHP_METHOD( ResourceBundle, __construct ) { - zval orig_this = *getThis(); + zend_error_handling error_handling; + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); return_value = getThis(); - resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); - + resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { - zend_object_store_ctor_failed(Z_OBJ(orig_this)); - ZEND_CTOR_MAKE_NULL(); + if (!EG(exception)) { + zend_throw_exception(IntlException_ce_ptr, "Constructor failed", 0); + } } + zend_restore_error_handling(&error_handling); } /* }}} */ @@ -157,7 +160,7 @@ proto ResourceBundle resourcebundle_create( string $locale [, string $bundlename PHP_FUNCTION( resourcebundle_create ) { object_init_ex( return_value, ResourceBundle_ce_ptr ); - resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); + resourcebundle_ctor(INTERNAL_FUNCTION_PARAM_PASSTHRU); if (Z_TYPE_P(return_value) == IS_OBJECT && Z_OBJ_P(return_value) == NULL) { RETURN_NULL(); } diff --git a/ext/intl/spoofchecker/spoofchecker_create.c b/ext/intl/spoofchecker/spoofchecker_create.c index b56c840961df4..abe1d8e9ccdce 100644 --- a/ext/intl/spoofchecker/spoofchecker_create.c +++ b/ext/intl/spoofchecker/spoofchecker_create.c @@ -30,15 +30,19 @@ PHP_METHOD(Spoofchecker, __construct) { int checks; SPOOFCHECKER_METHOD_INIT_VARS; + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, IntlException_ce_ptr, &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } SPOOFCHECKER_METHOD_FETCH_OBJECT_NO_CHECK; co->uspoof = uspoof_open(SPOOFCHECKER_ERROR_CODE_P(co)); - INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker", 1); + INTL_CTOR_CHECK_STATUS(co, "spoofchecker: unable to open ICU Spoof Checker"); /* Single-script enforcement is on by default. This fails for languages like Japanese that legally use multiple scripts within a single word, @@ -46,6 +50,7 @@ PHP_METHOD(Spoofchecker, __construct) */ checks = uspoof_getChecks(co->uspoof, SPOOFCHECKER_ERROR_CODE_P(co)); uspoof_setChecks(co->uspoof, checks & ~USPOOF_SINGLE_SCRIPT, SPOOFCHECKER_ERROR_CODE_P(co)); + zend_restore_error_handling(&error_handling); } /* }}} */ diff --git a/ext/intl/tests/breakiter___construct_error.phpt b/ext/intl/tests/breakiter___construct_error.phpt index 770f1403c71f7..bea65667faa11 100644 --- a/ext/intl/tests/breakiter___construct_error.phpt +++ b/ext/intl/tests/breakiter___construct_error.phpt @@ -7,32 +7,44 @@ IntlRuleBasedBreakIterator::__construct(): arg errors getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} +//missing ; at the end: +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+')); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator()); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator(1,2,3)); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', array())); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlRuleBasedBreakIterator('[\p{Letter}\uFFFD]+;[:number:]+;', true)); +} catch (IntlException $e) { + print_exception($e); +} --EXPECTF-- -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d -NULL - -Warning: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d - -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL - -Warning: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d +Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create RuleBasedBreakIterator from rules (parse error on line 1, offset 31) in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct() expects at least 1 parameter, 0 given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d +Exception: IntlRuleBasedBreakIterator::__construct() expects at most 2 parameters, 3 given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: bad arguments in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct() expects parameter 2 to be boolean, array given in %s on line %d -Warning: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d -NULL +Exception: IntlRuleBasedBreakIterator::__construct(): rbbi_create_instance: unable to create instance from compiled rules in %s on line %d diff --git a/ext/intl/tests/bug62017.phpt b/ext/intl/tests/bug62017.phpt index e5c216c1e2a42..2f3c816f99755 100644 --- a/ext/intl/tests/bug62017.phpt +++ b/ext/intl/tests/bug62017.phpt @@ -11,14 +11,14 @@ var_dump( datefmt_create('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "\xFF", IntlDateFormatter::GREGORIAN, 'a')); try { - new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", - IntlDateFormatter::GREGORIAN, "\x80"); -} -catch(IntlException $ie) { - echo $ie->getMessage().PHP_EOL; + var_dump( + new IntlDateFormatter('', IntlDateFormatter::NONE, IntlDateFormatter::NONE, "Europe/Lisbon", + IntlDateFormatter::GREGORIAN, "\x80")); +} catch (IntlException $e) { + echo PHP_EOL."Exception: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . PHP_EOL; } --EXPECTF-- Warning: datefmt_create(): datefmt_create: Time zone identifier given is not a valid UTF-8 string in %s on line %d NULL -datefmt_create: error converting pattern to UTF-16 +Exception: IntlDateFormatter::__construct(): datefmt_create: error converting pattern to UTF-16 in %sbug62017.php on line %d diff --git a/ext/intl/tests/bug62081.phpt b/ext/intl/tests/bug62081.phpt index 44ad4beec7fab..263023ffac66a 100644 --- a/ext/intl/tests/bug62081.phpt +++ b/ext/intl/tests/bug62081.phpt @@ -12,5 +12,8 @@ ini_set('intl.error_level', E_WARNING); $x = new IntlDateFormatter('en', 1, 1); var_dump($x->__construct('en', 1, 1)); --EXPECTF-- -Warning: IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice in %s on line %d -NULL +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: cannot call constructor twice' in %sbug62081.php:4 +Stack trace: +#0 %sbug62081.php(4): IntlDateFormatter->__construct('en', 1, 1) +#1 {main} + thrown in %sbug62081.php on line 4 diff --git a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt index cfd9338717365..d10ad42623bcd 100644 --- a/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt +++ b/ext/intl/tests/dateformat___construct_bad_tz_cal.phpt @@ -10,23 +10,32 @@ ini_set("intl.error_level", E_WARNING); ini_set("intl.default_locale", "pt_PT"); ini_set("date.timezone", 'Atlantic/Azores'); -var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone')); - -var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3)); - -var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass)); - - +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, 'bad timezone')); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, 3)); +} catch (IntlException $e) { + print_exception($e); +} +try { + var_dump(new IntlDateFormatter(NULL, 0, 0, NULL, new stdclass)); +} catch (IntlException $e) { + print_exception($e); +} ?> ==DONE== --EXPECTF-- -Warning: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: no such time zone: 'bad timezone' in %s on line %d -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -Warning: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d -NULL +Exception: IntlDateFormatter::__construct(): datefmt_create: Invalid calendar argument; should be an integer or an IntlCalendar instance in %s on line %d ==DONE== diff --git a/ext/intl/tests/dateformat_calendars_variant2.phpt b/ext/intl/tests/dateformat_calendars_variant2.phpt index b3b1701c55159..11a5026da0e66 100644 --- a/ext/intl/tests/dateformat_calendars_variant2.phpt +++ b/ext/intl/tests/dateformat_calendars_variant2.phpt @@ -42,5 +42,8 @@ string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12" string(47) "Sunday, January 1, 2012 at 5:12:00 AM GMT+05:12" string(48) "Sunday, Tevet 6, 5772 AM at 5:12:00 AM GMT+05:12" -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %sdateformat_calendars_variant2.php on line %d -==DONE== +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars_variant2.php:27 +Stack trace: +#0 %sdateformat_calendars_variant2.php(27): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1) +#1 {main} + thrown in %sdateformat_calendars_variant2.php on line 27 diff --git a/ext/intl/tests/formatter_fail.phpt b/ext/intl/tests/formatter_fail.phpt index c45b113bdba38..f61cb14878a25 100644 --- a/ext/intl/tests/formatter_fail.phpt +++ b/ext/intl/tests/formatter_fail.phpt @@ -11,24 +11,26 @@ function err($fmt) { } } +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + function crt($t, $l, $s) { - try { - $fmt = null; - switch(true) { - case $t == "O": - $fmt = new NumberFormatter($l, $s); - break; - case $t == "C": - $fmt = NumberFormatter::create($l, $s); - break; - case $t == "P": - $fmt = numfmt_create($l, $s); - break; - } - err($fmt); - } - catch(IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; + switch(true) { + case $t == "O": + try { + return new NumberFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } + break; + case $t == "C": + return NumberFormatter::create($l, $s); + break; + case $t == "P": + return numfmt_create($l, $s); + break; } } @@ -42,11 +44,11 @@ $args = array( try { $fmt = new NumberFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; } -catch(IntlException $ie) { - echo $ie->getMessage().PHP_EOL; -} - +err($fmt); $fmt = numfmt_create(); err($fmt); $fmt = NumberFormatter::create(); @@ -54,13 +56,16 @@ err($fmt); foreach($args as $arg) { $fmt = crt("O", $arg[0], $arg[1]); + err($fmt); $fmt = crt("C", $arg[0], $arg[1]); + err($fmt); $fmt = crt("P", $arg[0], $arg[1]); + err($fmt); } ?> --EXPECTF-- -Warning: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d +Exception: NumberFormatter::__construct() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d @@ -68,21 +73,27 @@ Warning: numfmt_create() expects at least 2 parameters, 0 given in %s on line %d Warning: NumberFormatter::create() expects at least 2 parameters, 0 given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' 'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' -Warning: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: NumberFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: NumberFormatter::create() expects parameter 1 to be string, array given in %s on line %d 'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: numfmt_create() expects parameter 1 to be string, array given in %s on line %d -IE: numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR -IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR -IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR -IE: numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR -IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR -IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR -IE: numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR +'numfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d +'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' +'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' +'numfmt_create: number formatter creation failed: U_UNSUPPORTED_ERROR' + +Exception: Constructor failed in %sformatter_fail.php on line %d +'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' +'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' +'numfmt_create: number formatter creation failed: U_MEMORY_ALLOCATION_ERROR' diff --git a/ext/intl/tests/formatter_format.phpt b/ext/intl/tests/formatter_format.phpt index 0fa88681d95ae..334ef49567cc2 100644 --- a/ext/intl/tests/formatter_format.phpt +++ b/ext/intl/tests/formatter_format.phpt @@ -50,14 +50,7 @@ function ut_main() $str_res .= "\nLocale is: $locale\n"; foreach( $styles as $style => $pattern ) { - try { - $fmt = ut_nfmt_create( $locale, $style, $pattern ); - } - catch (IntlException $ie) { - //$str_res .= "IE:".$ie->getMessage()."\n"; - $str_res .= "Bad formatter!\n"; - continue; - } + $fmt = ut_nfmt_create( $locale, $style, $pattern ); if(!$fmt) { $str_res .= "Bad formatter!\n"; diff --git a/ext/intl/tests/gregoriancalendar___construct_error.phpt b/ext/intl/tests/gregoriancalendar___construct_error.phpt index a28fa715e4241..d81809793eb36 100644 --- a/ext/intl/tests/gregoriancalendar___construct_error.phpt +++ b/ext/intl/tests/gregoriancalendar___construct_error.phpt @@ -8,23 +8,23 @@ if (!extension_loaded('intl')) getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7)); var_dump(intlgregcal_create_instance(1,2,3,4,5,6,7,8)); var_dump(intlgregcal_create_instance(1,2,3,4)); try { - new IntlGregorianCalendar(1,2,NULL,4); -} -catch (IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; + var_dump(new IntlGregorianCalendar(1,2,NULL,4)); +} catch (IntlException $e) { + print_exception($e); } try { - new IntlGregorianCalendar(1,2,3,4,NULL,array()); -} -catch (IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; + var_dump(new IntlGregorianCalendar(1,2,3,4,NULL,array())); +} catch (IntlException $e) { + print_exception($e); } - - --EXPECTF-- Warning: intlgregcal_create_instance(): intlgregcal_create_instance: too many arguments in %s on line %d @@ -36,6 +36,6 @@ NULL Warning: intlgregcal_create_instance(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d NULL -IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) -Warning: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d -IE: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: bad arguments +Exception: IntlGregorianCalendar::__construct(): intlgregcal_create_instance: no variant with 4 arguments (excluding trailing NULLs) in %s on line %d + +Exception: IntlGregorianCalendar::__construct() expects parameter 6 to be integer, array given in %s on line %d diff --git a/ext/intl/tests/msgfmt_fail.phpt b/ext/intl/tests/msgfmt_fail.phpt index 4b60b35abc2cf..7c76598c0d419 100644 --- a/ext/intl/tests/msgfmt_fail.phpt +++ b/ext/intl/tests/msgfmt_fail.phpt @@ -12,25 +12,26 @@ function err($fmt) { } } -function crt($t, $l, $s) { +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} - try { - $fmt = null; - switch(true) { - case $t == "O": - $fmt = new MessageFormatter($l, $s); - break; - case $t == "C": - $fmt = MessageFormatter::create($l, $s); - break; - case $t == "P": - $fmt = msgfmt_create($l, $s); - break; - } - err($fmt); - } - catch (IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; +function crt($t, $l, $s) { + switch(true) { + case $t == "O": + try { + return new MessageFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } + break; + case $t == "C": + return MessageFormatter::create($l, $s); + break; + case $t == "P": + return msgfmt_create($l, $s); + break; } } @@ -45,34 +46,40 @@ $args = array( try { $fmt = new MessageFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; } -catch(IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; -} +err($fmt); $fmt = msgfmt_create(); err($fmt); $fmt = MessageFormatter::create(); err($fmt); try { $fmt = new MessageFormatter('en'); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; } -catch(IntlException $ie) { - echo "IE: ".$ie->getMessage().PHP_EOL; -} +err($fmt); $fmt = msgfmt_create('en'); err($fmt); $fmt = MessageFormatter::create('en'); err($fmt); foreach($args as $arg) { - crt("O", $arg[0], $arg[1]); - crt("C", $arg[0], $arg[1]); - crt("P", $arg[0], $arg[1]); + $fmt = crt("O", $arg[0], $arg[1]); + err($fmt); + $fmt = crt("C", $arg[0], $arg[1]); + err($fmt); + $fmt = crt("P", $arg[0], $arg[1]); + err($fmt); } ?> --EXPECTF-- -IE: msgfmt_create: unable to parse input parameters +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d +'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' @@ -80,21 +87,26 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -IE: msgfmt_create: unable to parse input parameters +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d +'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d @@ -102,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' diff --git a/ext/intl/tests/msgfmt_fail2.phpt b/ext/intl/tests/msgfmt_fail2.phpt index eee2424a5030e..0ab99cf633968 100644 --- a/ext/intl/tests/msgfmt_fail2.phpt +++ b/ext/intl/tests/msgfmt_fail2.phpt @@ -12,10 +12,19 @@ function err($fmt) { } } +function print_exception($e) { + echo "\nException: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + function crt($t, $l, $s) { switch(true) { case $t == "O": - return new MessageFormatter($l, $s); + try { + return new MessageFormatter($l, $s); + } catch (IntlException $e) { + print_exception($e); + return null; + } break; case $t == "C": return MessageFormatter::create($l, $s); @@ -35,13 +44,23 @@ $args = array( array("en_US", "\xD0"), ); -$fmt = new MessageFormatter(); +try { + $fmt = new MessageFormatter(); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create(); err($fmt); $fmt = MessageFormatter::create(); -err($fmt); -$fmt = new MessageFormatter('en'); +err($fmt); +try { + $fmt = new MessageFormatter('en'); +} catch (IntlException $e) { + print_exception($e); + $fmt = null; +} err($fmt); $fmt = msgfmt_create('en'); err($fmt); @@ -59,7 +78,7 @@ foreach($args as $arg) { ?> --EXPECTF-- -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d @@ -68,7 +87,7 @@ Warning: msgfmt_create() expects exactly 2 parameters, 0 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 0 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d +Exception: MessageFormatter::__construct() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d @@ -76,14 +95,18 @@ Warning: msgfmt_create() expects exactly 2 parameters, 1 given in %s on line %d Warning: MessageFormatter::create() expects exactly 2 parameters, 1 given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' 'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' -Warning: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d +Exception: MessageFormatter::__construct() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' Warning: MessageFormatter::create() expects parameter 1 to be string, array given in %s on line %d @@ -91,12 +114,18 @@ Warning: MessageFormatter::create() expects parameter 1 to be string, array give Warning: msgfmt_create() expects parameter 1 to be string, array given in %s on line %d 'msgfmt_create: unable to parse input parameters: U_ILLEGAL_ARGUMENT_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' 'msgfmt_create: message formatter creation failed: U_PATTERN_SYNTAX_ERROR' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' 'msgfmt_create: message formatter creation failed: U_UNMATCHED_BRACES' + +Exception: Constructor failed in %smsgfmt_fail2.php on line %d 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' 'msgfmt_create: error converting pattern to UTF-16: U_INVALID_CHAR_FOUND' diff --git a/ext/intl/tests/msgfmt_parse.phpt b/ext/intl/tests/msgfmt_parse.phpt index 2eaf630010399..b9ec36374bcbd 100644 --- a/ext/intl/tests/msgfmt_parse.phpt +++ b/ext/intl/tests/msgfmt_parse.phpt @@ -36,15 +36,9 @@ function ut_main() foreach( $locales as $locale => $pattern ) { $str_res .= "\nLocale is: $locale\n"; - try { - $fmt = ut_msgfmt_create( $locale, $pattern ); - if(!$fmt) { - $str_res .= dump(intl_get_error_message())."\n"; - continue; - } - } - catch (\IntlException $ie) { - $str_res .= "IE: ".$ie->getMessage().PHP_EOL; + $fmt = ut_msgfmt_create( $locale, $pattern ); + if(!$fmt) { + $str_res .= dump(intl_get_error_message())."\n"; continue; } $str_res .= dump( ut_msgfmt_parse( $fmt, $results[$locale] ) ) . "\n"; @@ -109,7 +103,7 @@ array ( ) Locale is: root -IE: msgfmt_create: message formatter creation failed +'msgfmt_create: message formatter creation failed: U_ILLEGAL_ARGUMENT_ERROR' Locale is: fr array ( diff --git a/ext/intl/tests/resourcebundle_create.phpt b/ext/intl/tests/resourcebundle_create.phpt index 99492a698b0b3..2bf4f556a8609 100644 --- a/ext/intl/tests/resourcebundle_create.phpt +++ b/ext/intl/tests/resourcebundle_create.phpt @@ -14,7 +14,6 @@ function ut_main() { $str_res .= debug( $r1 ); $str_res .= print_r( $r1['teststring'], true)."\n"; - // non-root one $r1 = ut_resourcebundle_create( 'es', BUNDLE ); $str_res .= debug( $r1 ); @@ -25,22 +24,14 @@ function ut_main() { $str_res .= debug( $r1 ); $str_res .= print_r( $r1['testsring'], true); - try { - // fall out - $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false ); - } - catch (\IntlException $ie) { - $str_res .= "ie: ".$ie->getMessage().PHP_EOL; - } - - try { - // missing - $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' ); - } - catch (\IntlException $ie) { - $str_res .= "ie: ".$ie->getMessage().PHP_EOL; - } + // fall out + $r2 = ut_resourcebundle_create( 'en_US', BUNDLE, false ); + $str_res .= debug( $r2 ); + // missing + $r3 = ut_resourcebundle_create( 'en_US', 'nonexisting' ); + $str_res .= debug( $r3 ); + return $str_res; } @@ -65,5 +56,7 @@ ResourceBundle Object ) -127: U_USING_DEFAULT_WARNING -ie: resourcebundle_ctor: Cannot load libICU resource bundle -ie: resourcebundle_ctor: Cannot load libICU resource bundle +NULL + 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR +NULL + 2: resourcebundle_ctor: Cannot load libICU resource bundle: U_MISSING_RESOURCE_ERROR diff --git a/ext/intl/tests/ut_common.inc b/ext/intl/tests/ut_common.inc index 09be22bf5a633..9f72bacae4d50 100644 --- a/ext/intl/tests/ut_common.inc +++ b/ext/intl/tests/ut_common.inc @@ -132,7 +132,15 @@ function ut_coll_set_default( $coll ) function ut_nfmt_create( $locale, $style, $pattern = null ) { - return $GLOBALS['oo-mode'] ? new NumberFormatter( $locale, $style, $pattern ) : numfmt_create( $locale, $style, $pattern ); + if ($GLOBALS['oo-mode']) { + try { + return new NumberFormatter( $locale, $style, $pattern ); + } catch (Exception $e) { + return NULL; + } + } else { + return numfmt_create( $locale, $style, $pattern ); + } } function ut_nfmt_format( $fmt, $number, $type = null ) { @@ -392,7 +400,15 @@ function ut_datefmt_localtime( $fmt , $value , &$parse_pos=0 ) function ut_resourcebundle_create( $locale, $bundle, $fallback=true ) { - return $GLOBALS['oo-mode'] ? new ResourceBundle($locale, $bundle, $fallback): resourcebundle_create($locale, $bundle, $fallback); + if ($GLOBALS['oo-mode']) { + try { + return new ResourceBundle($locale, $bundle, $fallback); + } catch (Exception $e) { + return NULL; + } + } else { + return resourcebundle_create($locale, $bundle, $fallback); + } } function ut_resourcebundle_count($bundle ) { diff --git a/ext/intl/transliterator/transliterator_methods.c b/ext/intl/transliterator/transliterator_methods.c index 7be1412b1328f..d8b030a6d14ee 100644 --- a/ext/intl/transliterator/transliterator_methods.c +++ b/ext/intl/transliterator/transliterator_methods.c @@ -169,7 +169,7 @@ PHP_FUNCTION( transliterator_create_from_rules ) str_rules, str_rules_len, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* (I'm not a big fan of non-obvious flow control macros ). * This one checks the error value, destroys object and returns false */ - INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed", 0 ); + INTL_CTOR_CHECK_STATUS( to, "String conversion of rules to UTF-16 failed" ); /* Open ICU Transliterator. */ utrans = utrans_openU( id, ( sizeof( id ) - 1 ) / ( sizeof( *id ) ), (UTransDirection ) direction, @@ -197,7 +197,7 @@ PHP_FUNCTION( transliterator_create_from_rules ) } transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ - INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed", 0 ); + INTL_CTOR_CHECK_STATUS( to, "transliterator_create_from_rules: internal constructor call failed" ); } /* }}} */ @@ -228,10 +228,10 @@ PHP_FUNCTION( transliterator_create_inverse ) utrans = utrans_openInverse( to_orig->utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); INTL_CTOR_CHECK_STATUS( to, "transliterator_create_inverse: could not create " - "inverse ICU transliterator", 0 ); + "inverse ICU transliterator" ); transliterator_object_construct( object, utrans, TRANSLITERATOR_ERROR_CODE_P( to ) ); /* no need to close the transliterator manually on construction error */ - INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed", 0 ); + INTL_CTOR_CHECK_STATUS( to, "transliterator_create: internal constructor call failed" ); } /* }}} */ diff --git a/ext/pdo/pdo_dbh.c b/ext/pdo/pdo_dbh.c index 1796435c5fb02..ed541543f9a2d 100644 --- a/ext/pdo/pdo_dbh.c +++ b/ext/pdo/pdo_dbh.c @@ -209,15 +209,11 @@ static PHP_METHOD(PDO, dbh_constructor) char alt_dsn[512]; int call_factory = 1; zend_error_handling zeh; - int rv; - zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh TSRMLS_CC); - rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len, - &username, &usernamelen, &password, &passwordlen, &options); - zend_restore_error_handling(&zeh TSRMLS_CC); - - if (FAILURE == rv) { - ZEND_CTOR_MAKE_NULL(); + zend_replace_error_handling(EH_THROW, pdo_exception_ce, &zeh); + if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "s|s!s!a!", &data_source, &data_source_len, + &username, &usernamelen, &password, &passwordlen, &options)) { + zend_restore_error_handling(&zeh); return; } @@ -230,8 +226,8 @@ static PHP_METHOD(PDO, dbh_constructor) snprintf(alt_dsn, sizeof(alt_dsn), "pdo.dsn.%s", data_source); if (FAILURE == cfg_get_string(alt_dsn, &ini_dsn)) { + zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name"); - ZEND_CTOR_MAKE_NULL(); return; } @@ -239,8 +235,8 @@ static PHP_METHOD(PDO, dbh_constructor) colon = strchr(data_source, ':'); if (!colon) { + zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via INI: %s)", alt_dsn); - ZEND_CTOR_MAKE_NULL(); return; } } @@ -249,14 +245,14 @@ static PHP_METHOD(PDO, dbh_constructor) /* the specified URI holds connection details */ data_source = dsn_from_uri(data_source + sizeof("uri:")-1, alt_dsn, sizeof(alt_dsn)); if (!data_source) { + zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source URI"); - ZEND_CTOR_MAKE_NULL(); return; } colon = strchr(data_source, ':'); if (!colon) { + zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "invalid data source name (via URI)"); - ZEND_CTOR_MAKE_NULL(); return; } } @@ -266,8 +262,8 @@ static PHP_METHOD(PDO, dbh_constructor) if (!driver) { /* NB: don't want to include the data_source in the error message as * it might contain a password */ + zend_restore_error_handling(&zeh); zend_throw_exception_ex(php_pdo_get_exception(), 0, "could not find driver"); - ZEND_CTOR_MAKE_NULL(); return; } @@ -402,12 +398,16 @@ static PHP_METHOD(PDO, dbh_constructor) } ZEND_HASH_FOREACH_END(); } + zend_restore_error_handling(&zeh); return; } /* the connection failed; things will tidy up in free_storage */ /* XXX raise exception */ - ZEND_CTOR_MAKE_NULL(); + zend_restore_error_handling(&zeh); + if (!EG(exception)) { + zend_throw_exception(pdo_exception_ce, "Constructor failed", 0); + } } /* }}} */ @@ -465,11 +465,7 @@ static void pdo_stmt_construct(zend_execute_data *execute_data, pdo_stmt_t *stmt fcc.called_scope = Z_OBJCE_P(object); fcc.object = Z_OBJ_P(object); - if (zend_call_function(&fci, &fcc) == FAILURE) { - Z_OBJ_P(object) = NULL; - ZEND_CTOR_MAKE_NULL(); - object = NULL; /* marks failure */ - } else if (!Z_ISUNDEF(retval)) { + if (zend_call_function(&fci, &fcc) != FAILURE) { zval_ptr_dtor(&retval); } diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index ace865899e457..d221c9ed22606 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -113,8 +113,7 @@ ZEND_END_ARG_INFO() RETURN_FALSE; \ } \ -//The class is called PDORow in userland, it is called PDOStatement in the manual. -static PHP_FUNCTION(dbstmt_constructor) /* {{{ */ +static PHP_FUNCTION(dbrow_constructor) /* {{{ */ { zend_throw_exception_ex(php_pdo_get_exception(), 0, "You may not create a PDORow manually"); } @@ -2641,8 +2640,7 @@ static union _zend_function *row_get_ctor(zend_object *object) ctor.type = ZEND_INTERNAL_FUNCTION; ctor.function_name = zend_string_init("__construct", sizeof("__construct") - 1, 0); ctor.scope = pdo_row_ce; - //The class is called PDORow in userland, it is called PDOStatement in the manual. - ctor.handler = ZEND_FN(dbstmt_constructor); + ctor.handler = ZEND_FN(dbrow_constructor); ctor.fn_flags = ZEND_ACC_PUBLIC; return (union _zend_function*)&ctor; diff --git a/ext/pdo/tests/pdo_036.phpt b/ext/pdo/tests/pdo_036.phpt index 16a1597f3633f..a9fdc9315d9db 100644 --- a/ext/pdo/tests/pdo_036.phpt +++ b/ext/pdo/tests/pdo_036.phpt @@ -7,29 +7,22 @@ Testing PDORow and PDOStatement instances with Reflection $instance = new reflectionclass('pdostatement'); $x = $instance->newInstance(); +var_dump($x); -if ($x instanceof pdostatement) { - echo "Ok".PHP_EOL; -} -else { - echo "Failed to create instance of pdostatment"; -} - -try { - $instance = new reflectionclass('pdorow'); - $x = $instance->newInstance(); - echo "Failed to throw exception: ".var_export($x, true); -} -catch(PDOException $pe) { - if ($pe->getMessage() != "You may not create a PDORow manually") { - echo "PDOException has wrong message."; - } - else { - echo "Ok".PHP_EOL; - } -} +$instance = new reflectionclass('pdorow'); +$x = $instance->newInstance(); +var_dump($x); ?> --EXPECTF-- -Ok -Ok +object(PDOStatement)#%d (1) { + [%u|b%"queryString"]=> + NULL +} + +Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdo_036.php:8 +Stack trace: +#0 [internal function]: PDORow->__construct() +#1 %spdo_036.php(8): ReflectionClass->newInstance() +#2 {main} + thrown in %spdo_036.php on line 8 diff --git a/ext/pdo/tests/pdorow.phpt b/ext/pdo/tests/pdorow.phpt index fca40a1ee1a1a..727f60f2c7d3f 100644 --- a/ext/pdo/tests/pdorow.phpt +++ b/ext/pdo/tests/pdorow.phpt @@ -5,22 +5,12 @@ Trying instantiate a PDORow object manually --FILE-- getMessage() != "You may not create a PDORow manually") { - echo "PDOException has wrong message."; - } - else { - echo "Ok".PHP_EOL; - } -} -catch(\Exception $e) { - echo "Exception throw was not of type PDOException instead was ".get_class($e).PHP_EOL; -} +new PDORow; ?> --EXPECTF-- -Ok +Fatal error: Uncaught exception 'PDOException' with message 'You may not create a PDORow manually' in %spdorow.php:3 +Stack trace: +#0 %spdorow.php(3): PDORow->__construct() +#1 {main} + thrown in %spdorow.php on line 3 diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt index 0cabfe6aa39e3..2a890c963d080 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct.phpt @@ -28,8 +28,11 @@ MySQLPDOTest::skip(); try { - if (NULL !== ($db = @new PDO())) - printf("[001] Too few parameters\n"); + try { + if (NULL !== ($db = @new PDO())) + printf("[001] Too few parameters\n"); + } catch (Exception $ex) { + } print tryandcatch(2, '$db = new PDO(chr(0));'); print tryandcatch(3, '$db = new PDO("a" . chr(0) . "b");'); diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt index 8cd028fc5362c..5166958d24232 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_options.phpt @@ -67,8 +67,11 @@ MySQLPDOTest::skip(); PDO::MYSQL_ATTR_INIT_COMMAND => '', ); - if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type'))) - printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db); + try { + if (NULL !== ($db = @new PDO($dsn, $user, $pass, 'wrong type'))) + printf("[001] Expecting NULL got %s/%s\n", gettype($db), $db); + } catch (Exception $e) { + } if (!is_object($db = new PDO($dsn, $user, $pass, array()))) printf("[002] Expecting object got %s/%s¸\n", gettype($db), $db); diff --git a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt index 7e92ff2e9a5d3..87a69125bb21e 100644 --- a/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt +++ b/ext/pdo_mysql/tests/pdo_mysql___construct_uri.phpt @@ -68,9 +68,6 @@ MySQLPDOTest::skip(); print "done!"; ?> --EXPECTF-- -Warning: PDO::__construct(%s [002] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=%s'), invalid data source URI - -Warning: PDO::__construct(%s [003] URI=uri:file:%spdomuri.tst, DSN=mysql%sdbname=%s, File=%spdomuri.tst (%d bytes, 'mysql%sdbname=letshopeinvalid%s'), chr(0) test, invalid data source URI done! diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index 982a67ba8a258..d2a63a538a385 100644 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -1149,7 +1149,7 @@ PHP_METHOD(Phar, __construct) rv = zend_parse_parameters(ZEND_NUM_ARGS(), "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len); zend_restore_error_handling(&zeh TSRMLS_CC); if (rv == FAILURE) { - //Exception was thrown already + /* Exception was thrown already */ return; } } diff --git a/ext/phar/tests/badparameters.phpt b/ext/phar/tests/badparameters.phpt index 781c8a3f4bd57..7d5525b887ddc 100644 --- a/ext/phar/tests/badparameters.phpt +++ b/ext/phar/tests/badparameters.phpt @@ -7,16 +7,37 @@ phar.readonly=0 --FILE-- getMessage() . " in " . $e->getFile() . " on line " . $e->getLine() . "\n"; +} + Phar::mungServer('hi'); Phar::createDefaultStub(array()); Phar::loadPhar(array()); Phar::canCompress('hi'); -$a = new Phar(array()); -$a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar'); +try { + $a = new Phar(array()); +} catch (PharException $e) { + print_exception($e); +} +try { + $a = new Phar(dirname(__FILE__) . '/files/frontcontroller10.phar'); +} catch (PharException $e) { + print_exception($e); +} $a->convertToExecutable(array()); $a->convertToData(array()); -$b = new PharData(dirname(__FILE__) . '/whatever.tar'); -$c = new PharData(dirname(__FILE__) . '/whatever.zip'); +try { + $b = new PharData(dirname(__FILE__) . '/whatever.tar'); +} catch (PharException $e) { + print_exception($e); +} +try { + $c = new PharData(dirname(__FILE__) . '/whatever.zip'); +} catch (PharException $e) { + print_exception($e); +} $b->delete(array()); try { $a->delete('oops'); @@ -132,7 +153,7 @@ Warning: Phar::loadPhar() expects parameter 1 to be %string, array given in %sba Warning: Phar::canCompress() expects parameter 1 to be integer, %string given in %sbadparameters.php on line %d -Warning: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d +Exception: Phar::__construct() expects parameter 1 to be %string, array given in %sbadparameters.php on line %d Warning: Phar::convertToExecutable() expects parameter 1 to be integer, array given in %sbadparameters.php on line %d diff --git a/ext/phar/tests/bug60261.phpt b/ext/phar/tests/bug60261.phpt index 1b6cd7a7cd951..c27ff5b554742 100644 --- a/ext/phar/tests/bug60261.phpt +++ b/ext/phar/tests/bug60261.phpt @@ -14,6 +14,8 @@ try { ?> --EXPECTF-- - -Warning: Phar::__construct() expects at least 1 parameter, 0 given in %s on line %d -SplFileInfo::getLinkTarget(): Empty filename +Fatal error: Uncaught exception 'PharException' with message 'Phar::__construct() expects at least 1 parameter, 0 given' in %sbug60261.php:3 +Stack trace: +#0 %sbug60261.php(3): Phar->__construct() +#1 {main} + thrown in %sbug60261.php on line 3 diff --git a/ext/phar/tests/pharfileinfo_construct.phpt b/ext/phar/tests/pharfileinfo_construct.phpt index 2610095e6e18b..df00161d55645 100644 --- a/ext/phar/tests/pharfileinfo_construct.phpt +++ b/ext/phar/tests/pharfileinfo_construct.phpt @@ -47,8 +47,8 @@ echo $e->getMessage() . "\n"; --EXPECTF-- Cannot open phar file 'phar://%spharfileinfo_construct.phar/oops': internal corruption of phar "%spharfileinfo_construct.phar" (truncated entry) -Warning: PharFileInfo::__construct() expects parameter 1 to be %string, array given in %spharfileinfo_construct.php on line %d -Cannot access phar file entry '/oops/I/do/not/exist' in archive '%spharfileinfo_construct.phar' -Cannot call constructor twice -'%spharfileinfo_construct.php' is not a valid phar archive URL (must have at least phar://filename.phar) -===DONE=== \ No newline at end of file +Fatal error: Uncaught exception 'PharException' with message 'PharFileInfo::__construct() expects parameter 1 to be string, array given' in %spharfileinfo_construct.php:13 +Stack trace: +#0 %spharfileinfo_construct.php(13): PharFileInfo->__construct(Array) +#1 {main} + thrown in %spharfileinfo_construct.php on line 13 diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index e7aed4da8eae0..4dc0ed68683f2 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -1612,7 +1612,7 @@ ZEND_METHOD(reflection_function, __construct) } efree(lcname); } else { - //Exception has been thrown. + /* Exception has been thrown. */ return; } } From 2afca9f179fca2e127d5da3e1cc6cf50ff47339c Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 30 Mar 2015 21:48:54 +0300 Subject: [PATCH 13/13] Fixed test --- ext/intl/tests/dateformat_calendars.phpt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ext/intl/tests/dateformat_calendars.phpt b/ext/intl/tests/dateformat_calendars.phpt index 7de6356455e9a..13dde0f370417 100644 --- a/ext/intl/tests/dateformat_calendars.phpt +++ b/ext/intl/tests/dateformat_calendars.phpt @@ -41,5 +41,8 @@ string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12" string(44) "Sunday, January 1, 2012 5:12:00 AM GMT+05:12" string(42) "Sunday, Tevet 6, 5772 5:12:00 AM GMT+05:12" -Warning: IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object in %s on line %d -==DONE== +Fatal error: Uncaught exception 'IntlException' with message 'IntlDateFormatter::__construct(): datefmt_create: invalid value for calendar type; it must be one of IntlDateFormatter::TRADITIONAL (locale's default calendar) or IntlDateFormatter::GREGORIAN. Alternatively, it can be an IntlCalendar object' in %sdateformat_calendars.php:%d +Stack trace: +#0 %sdateformat_calendars.php(%d): IntlDateFormatter->__construct('en_US@calendar=...', 0, 0, 'GMT+05:12', -1) +#1 {main} + thrown in %sdateformat_calendars.php on line %d