diff --git a/php_phongo.c b/php_phongo.c index bbc7dd792..4d1270dce 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -3849,9 +3849,14 @@ PHP_FUNCTION(MongoDB_disabled___construct) /* {{{ */ PHP_FUNCTION(MongoDB_disabled___wakeup) /* {{{ */ { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_throw_exception(PHONGO_ERROR_RUNTIME, "%s", "MongoDB\\Driver objects cannot be serialized"); } /* }}} */ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index eff04abd9..3fc426bf2 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -73,15 +73,15 @@ static bool php_phongo_binary_init_from_hash(php_phongo_binary_t* intern, HashTa Construct a new BSON binary type */ static PHP_METHOD(Binary, __construct) { - php_phongo_binary_t* intern; zend_error_handling error_handling; + php_phongo_binary_t* intern; char* data; size_t data_len; zend_long type; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_BINARY_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &data, &data_len, &type) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -95,13 +95,17 @@ static PHP_METHOD(Binary, __construct) */ static PHP_METHOD(Binary, __set_state) { + zend_error_handling error_handling; php_phongo_binary_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_binary_ce); @@ -115,11 +119,15 @@ static PHP_METHOD(Binary, __set_state) Return the Binary's data string. */ static PHP_METHOD(Binary, __toString) { + zend_error_handling error_handling; php_phongo_binary_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_BINARY_OBJ_P(getThis()); @@ -130,13 +138,17 @@ static PHP_METHOD(Binary, __toString) */ static PHP_METHOD(Binary, getData) { + zend_error_handling error_handling; php_phongo_binary_t* intern; intern = Z_BINARY_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRINGL(intern->data, intern->data_len); } /* }}} */ @@ -145,13 +157,17 @@ static PHP_METHOD(Binary, getData) */ static PHP_METHOD(Binary, getType) { + zend_error_handling error_handling; php_phongo_binary_t* intern; intern = Z_BINARY_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->type); } /* }}} */ @@ -160,13 +176,17 @@ static PHP_METHOD(Binary, getType) */ static PHP_METHOD(Binary, jsonSerialize) { + zend_error_handling error_handling; php_phongo_binary_t* intern; char type[3]; int type_len; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_BINARY_OBJ_P(getThis()); @@ -186,6 +206,7 @@ static PHP_METHOD(Binary, jsonSerialize) */ static PHP_METHOD(Binary, serialize) { + zend_error_handling error_handling; php_phongo_binary_t* intern; zval retval; php_serialize_data_t var_hash; @@ -193,9 +214,12 @@ static PHP_METHOD(Binary, serialize) intern = Z_BINARY_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "data", intern->data, intern->data_len); @@ -216,8 +240,8 @@ static PHP_METHOD(Binary, serialize) */ static PHP_METHOD(Binary, unserialize) { - php_phongo_binary_t* intern; zend_error_handling error_handling; + php_phongo_binary_t* intern; char* serialized; size_t serialized_len; zval props; @@ -226,7 +250,6 @@ static PHP_METHOD(Binary, unserialize) intern = Z_BINARY_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 3ae4e230f..eb1b80822 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -71,13 +71,17 @@ static bool php_phongo_dbpointer_init_from_hash(php_phongo_dbpointer_t* intern, Return the DBPointer's namespace string and ObjectId. */ static PHP_METHOD(DBPointer, __toString) { + zend_error_handling error_handling; php_phongo_dbpointer_t* intern; char* retval; int retval_len; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_DBPOINTER_OBJ_P(getThis()); @@ -90,13 +94,17 @@ static PHP_METHOD(DBPointer, __toString) */ static PHP_METHOD(DBPointer, jsonSerialize) { + zend_error_handling error_handling; php_phongo_dbpointer_t* intern; zval zdb_pointer; zval zoid; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_DBPOINTER_OBJ_P(getThis()); @@ -114,6 +122,7 @@ static PHP_METHOD(DBPointer, jsonSerialize) */ static PHP_METHOD(DBPointer, serialize) { + zend_error_handling error_handling; php_phongo_dbpointer_t* intern; zval retval; php_serialize_data_t var_hash; @@ -121,9 +130,12 @@ static PHP_METHOD(DBPointer, serialize) intern = Z_DBPOINTER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "ref", intern->ref, intern->ref_len); @@ -144,8 +156,8 @@ static PHP_METHOD(DBPointer, serialize) */ static PHP_METHOD(DBPointer, unserialize) { - php_phongo_dbpointer_t* intern; zend_error_handling error_handling; + php_phongo_dbpointer_t* intern; char* serialized; size_t serialized_len; zval props; @@ -154,7 +166,6 @@ static PHP_METHOD(DBPointer, unserialize) intern = Z_DBPOINTER_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 3247033ff..d5d75c7c2 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -60,14 +60,14 @@ static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t* intern Construct a new BSON Decimal128 type */ static PHP_METHOD(Decimal128, __construct) { - php_phongo_decimal128_t* intern; zend_error_handling error_handling; + php_phongo_decimal128_t* intern; char* value; size_t value_len; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_DECIMAL128_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &value, &value_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -81,13 +81,17 @@ static PHP_METHOD(Decimal128, __construct) */ static PHP_METHOD(Decimal128, __set_state) { + zend_error_handling error_handling; php_phongo_decimal128_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_decimal128_ce); @@ -101,14 +105,18 @@ static PHP_METHOD(Decimal128, __set_state) */ static PHP_METHOD(Decimal128, __toString) { + zend_error_handling error_handling; php_phongo_decimal128_t* intern; char outbuf[BSON_DECIMAL128_STRING]; intern = Z_DECIMAL128_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bson_decimal128_to_string(&intern->decimal, outbuf); @@ -119,12 +127,16 @@ static PHP_METHOD(Decimal128, __toString) */ static PHP_METHOD(Decimal128, jsonSerialize) { + zend_error_handling error_handling; php_phongo_decimal128_t* intern; char outbuf[BSON_DECIMAL128_STRING] = ""; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_DECIMAL128_OBJ_P(getThis()); @@ -137,6 +149,7 @@ static PHP_METHOD(Decimal128, jsonSerialize) */ static PHP_METHOD(Decimal128, serialize) { + zend_error_handling error_handling; php_phongo_decimal128_t* intern; zval retval; php_serialize_data_t var_hash; @@ -145,9 +158,12 @@ static PHP_METHOD(Decimal128, serialize) intern = Z_DECIMAL128_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bson_decimal128_to_string(&intern->decimal, outbuf); array_init_size(&retval, 1); @@ -168,8 +184,8 @@ static PHP_METHOD(Decimal128, serialize) */ static PHP_METHOD(Decimal128, unserialize) { - php_phongo_decimal128_t* intern; zend_error_handling error_handling; + php_phongo_decimal128_t* intern; char* serialized; size_t serialized_len; zval props; @@ -178,7 +194,6 @@ static PHP_METHOD(Decimal128, unserialize) intern = Z_DECIMAL128_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 3c92b9ae5..2ef0af86c 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -70,11 +70,15 @@ static bool php_phongo_int64_init_from_hash(php_phongo_int64_t* intern, HashTabl Return the Int64's value as a string. */ static PHP_METHOD(Int64, __toString) { + zend_error_handling error_handling; php_phongo_int64_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_INT64_OBJ_P(getThis()); @@ -85,11 +89,15 @@ static PHP_METHOD(Int64, __toString) */ static PHP_METHOD(Int64, jsonSerialize) { + zend_error_handling error_handling; php_phongo_int64_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_INT64_OBJ_P(getThis()); @@ -102,14 +110,18 @@ static PHP_METHOD(Int64, jsonSerialize) */ static PHP_METHOD(Int64, serialize) { + zend_error_handling error_handling; php_phongo_int64_t* intern; zval retval; php_serialize_data_t var_hash; smart_str buf = { 0 }; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_INT64_OBJ_P(getThis()); @@ -131,8 +143,8 @@ static PHP_METHOD(Int64, serialize) */ static PHP_METHOD(Int64, unserialize) { - php_phongo_int64_t* intern; zend_error_handling error_handling; + php_phongo_int64_t* intern; char* serialized; size_t serialized_len; zval props; @@ -141,7 +153,6 @@ static PHP_METHOD(Int64, unserialize) intern = Z_INT64_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index a916b5f6a..1b6bfd874 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -78,15 +78,15 @@ static bool php_phongo_javascript_init_from_hash(php_phongo_javascript_t* intern be evaluated. Note that this type cannot be represented as Extended JSON. */ static PHP_METHOD(Javascript, __construct) { - php_phongo_javascript_t* intern; zend_error_handling error_handling; + php_phongo_javascript_t* intern; char* code; size_t code_len; zval* scope = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_JAVASCRIPT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|A!", &code, &code_len, &scope) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -100,13 +100,17 @@ static PHP_METHOD(Javascript, __construct) */ static PHP_METHOD(Javascript, __set_state) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_javascript_ce); @@ -120,11 +124,15 @@ static PHP_METHOD(Javascript, __set_state) Return the Javascript's code string. */ static PHP_METHOD(Javascript, __toString) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -135,11 +143,15 @@ static PHP_METHOD(Javascript, __toString) */ static PHP_METHOD(Javascript, getCode) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -150,11 +162,15 @@ static PHP_METHOD(Javascript, getCode) */ static PHP_METHOD(Javascript, getScope) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -182,11 +198,15 @@ static PHP_METHOD(Javascript, getScope) */ static PHP_METHOD(Javascript, jsonSerialize) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_JAVASCRIPT_OBJ_P(getThis()); @@ -210,6 +230,7 @@ static PHP_METHOD(Javascript, jsonSerialize) */ static PHP_METHOD(Javascript, serialize) { + zend_error_handling error_handling; php_phongo_javascript_t* intern; zval retval; php_phongo_bson_state state; @@ -220,9 +241,12 @@ static PHP_METHOD(Javascript, serialize) intern = Z_JAVASCRIPT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (intern->scope && intern->scope->len) { if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->scope), intern->scope->len, &state)) { @@ -252,8 +276,8 @@ static PHP_METHOD(Javascript, serialize) */ static PHP_METHOD(Javascript, unserialize) { - php_phongo_javascript_t* intern; zend_error_handling error_handling; + php_phongo_javascript_t* intern; char* serialized; size_t serialized_len; zval props; @@ -262,7 +286,6 @@ static PHP_METHOD(Javascript, unserialize) intern = Z_JAVASCRIPT_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/MaxKey.c b/src/BSON/MaxKey.c index 0ffa4200c..7e20867e3 100644 --- a/src/BSON/MaxKey.c +++ b/src/BSON/MaxKey.c @@ -32,11 +32,15 @@ zend_class_entry* php_phongo_maxkey_ce; */ static PHP_METHOD(MaxKey, __set_state) { - zval* array; + zend_error_handling error_handling; + zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_maxkey_ce); } /* }}} */ @@ -45,9 +49,14 @@ static PHP_METHOD(MaxKey, __set_state) */ static PHP_METHOD(MaxKey, jsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(return_value, 1); ADD_ASSOC_LONG_EX(return_value, "$maxKey", 1); @@ -57,6 +66,15 @@ static PHP_METHOD(MaxKey, jsonSerialize) */ static PHP_METHOD(MaxKey, serialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); + return; + } + zend_restore_error_handling(&error_handling); + RETURN_STRING(""); } /* }}} */ @@ -69,7 +87,6 @@ static PHP_METHOD(MaxKey, unserialize) size_t serialized_len; zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/MinKey.c b/src/BSON/MinKey.c index 875645916..cfcee3845 100644 --- a/src/BSON/MinKey.c +++ b/src/BSON/MinKey.c @@ -32,11 +32,15 @@ zend_class_entry* php_phongo_minkey_ce; */ static PHP_METHOD(MinKey, __set_state) { - zval* array; + zend_error_handling error_handling; + zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_minkey_ce); } /* }}} */ @@ -45,9 +49,14 @@ static PHP_METHOD(MinKey, __set_state) */ static PHP_METHOD(MinKey, jsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(return_value, 1); ADD_ASSOC_LONG_EX(return_value, "$minKey", 1); @@ -57,6 +66,15 @@ static PHP_METHOD(MinKey, jsonSerialize) */ static PHP_METHOD(MinKey, serialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); + return; + } + zend_restore_error_handling(&error_handling); + RETURN_STRING(""); } /* }}} */ @@ -69,7 +87,6 @@ static PHP_METHOD(MinKey, unserialize) size_t serialized_len; zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index fa7e91831..78a7ebd69 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -84,14 +84,14 @@ static bool php_phongo_objectid_init_from_hash(php_phongo_objectid_t* intern, Ha Constructs a new BSON ObjectId type, optionally from a hex string. */ static PHP_METHOD(ObjectId, __construct) { - php_phongo_objectid_t* intern; zend_error_handling error_handling; + php_phongo_objectid_t* intern; char* id = NULL; size_t id_len; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_OBJECTID_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &id, &id_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -109,14 +109,18 @@ static PHP_METHOD(ObjectId, __construct) */ static PHP_METHOD(ObjectId, getTimestamp) { + zend_error_handling error_handling; php_phongo_objectid_t* intern; bson_oid_t tmp_oid; intern = Z_OBJECTID_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bson_oid_init_from_string(&tmp_oid, intern->oid); RETVAL_LONG(bson_oid_get_time_t(&tmp_oid)); @@ -126,13 +130,17 @@ static PHP_METHOD(ObjectId, getTimestamp) */ static PHP_METHOD(ObjectId, __set_state) { + zend_error_handling error_handling; php_phongo_objectid_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_objectid_ce); @@ -146,13 +154,17 @@ static PHP_METHOD(ObjectId, __set_state) */ static PHP_METHOD(ObjectId, __toString) { + zend_error_handling error_handling; php_phongo_objectid_t* intern; intern = Z_OBJECTID_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRINGL(intern->oid, PHONGO_OID_LEN); } /* }}} */ @@ -161,11 +173,15 @@ static PHP_METHOD(ObjectId, __toString) */ static PHP_METHOD(ObjectId, jsonSerialize) { + zend_error_handling error_handling; php_phongo_objectid_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_OBJECTID_OBJ_P(getThis()); @@ -177,6 +193,7 @@ static PHP_METHOD(ObjectId, jsonSerialize) */ static PHP_METHOD(ObjectId, serialize) { + zend_error_handling error_handling; php_phongo_objectid_t* intern; zval retval; php_serialize_data_t var_hash; @@ -184,9 +201,12 @@ static PHP_METHOD(ObjectId, serialize) intern = Z_OBJECTID_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 1); ADD_ASSOC_STRINGL(&retval, "oid", intern->oid, PHONGO_OID_LEN); @@ -206,8 +226,8 @@ static PHP_METHOD(ObjectId, serialize) */ static PHP_METHOD(ObjectId, unserialize) { - php_phongo_objectid_t* intern; zend_error_handling error_handling; + php_phongo_objectid_t* intern; char* serialized; size_t serialized_len; zval props; @@ -216,7 +236,6 @@ static PHP_METHOD(ObjectId, unserialize) intern = Z_OBJECTID_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 1d6accc9d..7db77f7f2 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -86,16 +86,16 @@ static bool php_phongo_regex_init_from_hash(php_phongo_regex_t* intern, HashTabl Constructs a new BSON regular expression type. */ static PHP_METHOD(Regex, __construct) { - php_phongo_regex_t* intern; zend_error_handling error_handling; + php_phongo_regex_t* intern; char* pattern; size_t pattern_len; char* flags = NULL; size_t flags_len = 0; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_REGEX_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|s", &pattern, &pattern_len, &flags, &flags_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -109,13 +109,17 @@ static PHP_METHOD(Regex, __construct) */ static PHP_METHOD(Regex, getPattern) { + zend_error_handling error_handling; php_phongo_regex_t* intern; intern = Z_REGEX_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRINGL(intern->pattern, intern->pattern_len); } /* }}} */ @@ -124,13 +128,17 @@ static PHP_METHOD(Regex, getPattern) */ static PHP_METHOD(Regex, getFlags) { + zend_error_handling error_handling; php_phongo_regex_t* intern; intern = Z_REGEX_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRINGL(intern->flags, intern->flags_len); } /* }}} */ @@ -139,13 +147,17 @@ static PHP_METHOD(Regex, getFlags) */ static PHP_METHOD(Regex, __set_state) { + zend_error_handling error_handling; php_phongo_regex_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_regex_ce); @@ -159,15 +171,19 @@ static PHP_METHOD(Regex, __set_state) Returns a string in the form: /pattern/flags */ static PHP_METHOD(Regex, __toString) { + zend_error_handling error_handling; php_phongo_regex_t* intern; char* regex; int regex_len; intern = Z_REGEX_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); regex_len = spprintf(®ex, 0, "/%s/%s", intern->pattern, intern->flags); RETVAL_STRINGL(regex, regex_len); @@ -178,11 +194,15 @@ static PHP_METHOD(Regex, __toString) */ static PHP_METHOD(Regex, jsonSerialize) { + zend_error_handling error_handling; php_phongo_regex_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_REGEX_OBJ_P(getThis()); @@ -195,6 +215,7 @@ static PHP_METHOD(Regex, jsonSerialize) */ static PHP_METHOD(Regex, serialize) { + zend_error_handling error_handling; php_phongo_regex_t* intern; zval retval; php_serialize_data_t var_hash; @@ -202,9 +223,12 @@ static PHP_METHOD(Regex, serialize) intern = Z_REGEX_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 2); ADD_ASSOC_STRINGL(&retval, "pattern", intern->pattern, intern->pattern_len); @@ -225,8 +249,8 @@ static PHP_METHOD(Regex, serialize) */ static PHP_METHOD(Regex, unserialize) { - php_phongo_regex_t* intern; zend_error_handling error_handling; + php_phongo_regex_t* intern; char* serialized; size_t serialized_len; zval props; @@ -235,7 +259,6 @@ static PHP_METHOD(Regex, unserialize) intern = Z_REGEX_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 5ec9526c1..0409fc63e 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -62,11 +62,15 @@ static bool php_phongo_symbol_init_from_hash(php_phongo_symbol_t* intern, HashTa Return the Symbol's symbol string. */ static PHP_METHOD(Symbol, __toString) { + zend_error_handling error_handling; php_phongo_symbol_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_SYMBOL_OBJ_P(getThis()); @@ -77,11 +81,15 @@ static PHP_METHOD(Symbol, __toString) */ static PHP_METHOD(Symbol, jsonSerialize) { + zend_error_handling error_handling; php_phongo_symbol_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_SYMBOL_OBJ_P(getThis()); @@ -93,6 +101,7 @@ static PHP_METHOD(Symbol, jsonSerialize) */ static PHP_METHOD(Symbol, serialize) { + zend_error_handling error_handling; php_phongo_symbol_t* intern; zval retval; php_serialize_data_t var_hash; @@ -100,9 +109,12 @@ static PHP_METHOD(Symbol, serialize) intern = Z_SYMBOL_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 1); ADD_ASSOC_STRINGL(&retval, "symbol", intern->symbol, intern->symbol_len); @@ -122,8 +134,8 @@ static PHP_METHOD(Symbol, serialize) */ static PHP_METHOD(Symbol, unserialize) { - php_phongo_symbol_t* intern; zend_error_handling error_handling; + php_phongo_symbol_t* intern; char* serialized; size_t serialized_len; zval props; @@ -132,7 +144,6 @@ static PHP_METHOD(Symbol, unserialize) intern = Z_SYMBOL_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 60167cc2e..a0f90236c 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -94,13 +94,13 @@ static bool php_phongo_timestamp_init_from_hash(php_phongo_timestamp_t* intern, 4-byte timestamp. */ static PHP_METHOD(Timestamp, __construct) { - php_phongo_timestamp_t* intern; zend_error_handling error_handling; + php_phongo_timestamp_t* intern; zval * increment = NULL, *timestamp = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_TIMESTAMP_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "zz", &increment, ×tamp) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -137,13 +137,17 @@ static PHP_METHOD(Timestamp, __construct) */ static PHP_METHOD(Timestamp, getIncrement) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; intern = Z_TIMESTAMP_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_LONG(intern->increment); } /* }}} */ @@ -152,13 +156,17 @@ static PHP_METHOD(Timestamp, getIncrement) */ static PHP_METHOD(Timestamp, getTimestamp) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; intern = Z_TIMESTAMP_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_LONG(intern->timestamp); } /* }}} */ @@ -167,13 +175,17 @@ static PHP_METHOD(Timestamp, getTimestamp) */ static PHP_METHOD(Timestamp, __set_state) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_timestamp_ce); @@ -187,15 +199,19 @@ static PHP_METHOD(Timestamp, __set_state) Returns a string in the form: [increment:timestamp] */ static PHP_METHOD(Timestamp, __toString) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; char* retval; int retval_len; intern = Z_TIMESTAMP_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); retval_len = spprintf(&retval, 0, "[%" PRIu32 ":%" PRIu32 "]", intern->increment, intern->timestamp); RETVAL_STRINGL(retval, retval_len); @@ -206,11 +222,15 @@ static PHP_METHOD(Timestamp, __toString) */ static PHP_METHOD(Timestamp, jsonSerialize) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_TIMESTAMP_OBJ_P(getThis()); @@ -230,6 +250,7 @@ static PHP_METHOD(Timestamp, jsonSerialize) */ static PHP_METHOD(Timestamp, serialize) { + zend_error_handling error_handling; php_phongo_timestamp_t* intern; zval retval; php_serialize_data_t var_hash; @@ -241,9 +262,12 @@ static PHP_METHOD(Timestamp, serialize) intern = Z_TIMESTAMP_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); s_timestamp_len = snprintf(s_timestamp, sizeof(s_timestamp), "%" PRIu32, intern->timestamp); @@ -267,8 +291,8 @@ static PHP_METHOD(Timestamp, serialize) */ static PHP_METHOD(Timestamp, unserialize) { - php_phongo_timestamp_t* intern; zend_error_handling error_handling; + php_phongo_timestamp_t* intern; char* serialized; size_t serialized_len; zval props; @@ -277,7 +301,6 @@ static PHP_METHOD(Timestamp, unserialize) intern = Z_TIMESTAMP_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d552b32c4..fa721c7cb 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -118,13 +118,13 @@ static bool php_phongo_utcdatetime_init_from_date(php_phongo_utcdatetime_t* inte current time. */ static PHP_METHOD(UTCDateTime, __construct) { - php_phongo_utcdatetime_t* intern; zend_error_handling error_handling; + php_phongo_utcdatetime_t* intern; zval* milliseconds = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_UTCDATETIME_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|z!", &milliseconds) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -174,13 +174,17 @@ static PHP_METHOD(UTCDateTime, __construct) */ static PHP_METHOD(UTCDateTime, __set_state) { + zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_utcdatetime_ce); @@ -194,13 +198,17 @@ static PHP_METHOD(UTCDateTime, __set_state) Returns the UTCDateTime's milliseconds as a string */ static PHP_METHOD(UTCDateTime, __toString) { + zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; intern = Z_UTCDATETIME_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); ZVAL_INT64_STRING(return_value, intern->milliseconds); } /* }}} */ @@ -209,6 +217,7 @@ static PHP_METHOD(UTCDateTime, __toString) Returns a DateTime object representing this UTCDateTime */ static PHP_METHOD(UTCDateTime, toDateTime) { + zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; php_date_obj* datetime_obj; char* sec; @@ -216,9 +225,12 @@ static PHP_METHOD(UTCDateTime, toDateTime) intern = Z_UTCDATETIME_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_date_get_date_ce()); datetime_obj = Z_PHPDATE_P(return_value); @@ -239,11 +251,15 @@ static PHP_METHOD(UTCDateTime, toDateTime) */ static PHP_METHOD(UTCDateTime, jsonSerialize) { + zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_UTCDATETIME_OBJ_P(getThis()); @@ -262,6 +278,7 @@ static PHP_METHOD(UTCDateTime, jsonSerialize) */ static PHP_METHOD(UTCDateTime, serialize) { + zend_error_handling error_handling; php_phongo_utcdatetime_t* intern; zval retval; php_serialize_data_t var_hash; @@ -269,9 +286,12 @@ static PHP_METHOD(UTCDateTime, serialize) intern = Z_UTCDATETIME_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(&retval, 1); ADD_ASSOC_INT64_AS_STRING(&retval, "milliseconds", intern->milliseconds); @@ -291,8 +311,8 @@ static PHP_METHOD(UTCDateTime, serialize) */ static PHP_METHOD(UTCDateTime, unserialize) { - php_phongo_utcdatetime_t* intern; zend_error_handling error_handling; + php_phongo_utcdatetime_t* intern; char* serialized; size_t serialized_len; zval props; @@ -301,7 +321,6 @@ static PHP_METHOD(UTCDateTime, unserialize) intern = Z_UTCDATETIME_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/Undefined.c b/src/BSON/Undefined.c index 7f76e6b95..527e0ec22 100644 --- a/src/BSON/Undefined.c +++ b/src/BSON/Undefined.c @@ -32,6 +32,15 @@ zend_class_entry* php_phongo_undefined_ce; Return the empty string. */ static PHP_METHOD(Undefined, __toString) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); + return; + } + zend_restore_error_handling(&error_handling); + RETURN_STRINGL("", 0); } /* }}} */ @@ -39,9 +48,14 @@ static PHP_METHOD(Undefined, __toString) */ static PHP_METHOD(Undefined, jsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init_size(return_value, 1); ADD_ASSOC_BOOL_EX(return_value, "$undefined", 1); @@ -51,6 +65,15 @@ static PHP_METHOD(Undefined, jsonSerialize) */ static PHP_METHOD(Undefined, serialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); + if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); + return; + } + zend_restore_error_handling(&error_handling); + RETURN_STRING(""); } /* }}} */ @@ -63,7 +86,6 @@ static PHP_METHOD(Undefined, unserialize) size_t serialized_len; zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/BSON/functions.c b/src/BSON/functions.c index 02ae6ecdb..2420f576e 100644 --- a/src/BSON/functions.c +++ b/src/BSON/functions.c @@ -34,12 +34,16 @@ typedef enum { Returns the BSON representation of a PHP value */ PHP_FUNCTION(MongoDB_BSON_fromPHP) { - zval* data; - bson_t* bson; + zend_error_handling error_handling; + zval* data; + bson_t* bson; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &data) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bson = bson_new(); php_phongo_zval_to_bson(data, PHONGO_BSON_NONE, bson, NULL); @@ -52,6 +56,7 @@ PHP_FUNCTION(MongoDB_BSON_fromPHP) Returns the PHP representation of a BSON value, optionally converting it into a custom class */ PHP_FUNCTION(MongoDB_BSON_toPHP) { + zend_error_handling error_handling; char* data; size_t data_len; zval* typemap = NULL; @@ -59,9 +64,12 @@ PHP_FUNCTION(MongoDB_BSON_toPHP) PHONGO_BSON_INIT_STATE(state); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a!", &data, &data_len, &typemap) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_bson_typemap_to_state(typemap, &state.map)) { return; @@ -82,14 +90,18 @@ PHP_FUNCTION(MongoDB_BSON_toPHP) Returns the BSON representation of a JSON value */ PHP_FUNCTION(MongoDB_BSON_fromJSON) { - char* json; - size_t json_len; - bson_t bson = BSON_INITIALIZER; - bson_error_t error = { 0 }; + zend_error_handling error_handling; + char* json; + size_t json_len; + bson_t bson = BSON_INITIALIZER; + bson_error_t error = { 0 }; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &json, &json_len) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (bson_init_from_json(&bson, (const char*) json, json_len, &error)) { RETVAL_STRINGL((const char*) bson_get_data(&bson), bson.len); @@ -101,17 +113,21 @@ PHP_FUNCTION(MongoDB_BSON_fromJSON) static void phongo_bson_to_json(INTERNAL_FUNCTION_PARAMETERS, php_phongo_json_mode_t mode) { - char* data; - size_t data_len; - const bson_t* bson; - bool eof = false; - bson_reader_t* reader; - char* json = NULL; - size_t json_len; - + zend_error_handling error_handling; + char* data; + size_t data_len; + const bson_t* bson; + bool eof = false; + bson_reader_t* reader; + char* json = NULL; + size_t json_len; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &data, &data_len) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); reader = bson_reader_new_from_data((const unsigned char*) data, data_len); bson = bson_reader_read(reader, NULL); diff --git a/src/MongoDB/BulkWrite.c b/src/MongoDB/BulkWrite.c index c2866d9b0..490dee324 100644 --- a/src/MongoDB/BulkWrite.c +++ b/src/MongoDB/BulkWrite.c @@ -312,14 +312,14 @@ static bool php_phongo_bulkwrite_delete_apply_options(bson_t* boptions, zval* zo Constructs a new BulkWrite */ static PHP_METHOD(BulkWrite, __construct) { - php_phongo_bulkwrite_t* intern; zend_error_handling error_handling; + php_phongo_bulkwrite_t* intern; zval* options = NULL; zend_bool ordered = 1; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_BULKWRITE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -347,6 +347,7 @@ static PHP_METHOD(BulkWrite, __construct) Adds an insert operation to the BulkWrite */ static PHP_METHOD(BulkWrite, insert) { + zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval* zdocument; bson_t bdocument = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -356,9 +357,12 @@ static PHP_METHOD(BulkWrite, insert) intern = Z_BULKWRITE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &zdocument) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bson_flags |= PHONGO_BSON_RETURN_ID; @@ -392,6 +396,7 @@ static PHP_METHOD(BulkWrite, insert) Adds an update operation to the BulkWrite */ static PHP_METHOD(BulkWrite, update) { + zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval * zquery, *zupdate, *zoptions = NULL; bson_t bquery = BSON_INITIALIZER, bupdate = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -399,9 +404,12 @@ static PHP_METHOD(BulkWrite, update) intern = Z_BULKWRITE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "AA|a!", &zquery, &zupdate, &zoptions) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL); @@ -455,6 +463,7 @@ static PHP_METHOD(BulkWrite, update) Adds a delete operation to the BulkWrite */ static PHP_METHOD(BulkWrite, delete) { + zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; zval * zquery, *zoptions = NULL; bson_t bquery = BSON_INITIALIZER, boptions = BSON_INITIALIZER; @@ -462,9 +471,12 @@ static PHP_METHOD(BulkWrite, delete) intern = Z_BULKWRITE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &zquery, &zoptions) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_zval_to_bson(zquery, PHONGO_BSON_NONE, &bquery, NULL); @@ -499,13 +511,17 @@ static PHP_METHOD(BulkWrite, delete) Returns the number of operations that have been added to the BulkWrite */ static PHP_METHOD(BulkWrite, count) { + zend_error_handling error_handling; php_phongo_bulkwrite_t* intern; intern = Z_BULKWRITE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->num_ops); } /* }}} */ diff --git a/src/MongoDB/ClientEncryption.c b/src/MongoDB/ClientEncryption.c index 01dba042d..ef8703a77 100644 --- a/src/MongoDB/ClientEncryption.c +++ b/src/MongoDB/ClientEncryption.c @@ -38,7 +38,6 @@ static PHP_METHOD(ClientEncryption, createDataKey) intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|a!", &kms_provider, &kms_provider_len, &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -60,7 +59,6 @@ static PHP_METHOD(ClientEncryption, encrypt) intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a!", &value, &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -81,7 +79,6 @@ static PHP_METHOD(ClientEncryption, decrypt) intern = Z_CLIENTENCRYPTION_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &ciphertext, php_phongo_binary_interface_ce) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/Command.c b/src/MongoDB/Command.c index 7829cb7af..5401a06ae 100644 --- a/src/MongoDB/Command.c +++ b/src/MongoDB/Command.c @@ -101,14 +101,14 @@ static bool php_phongo_command_init(php_phongo_command_t* intern, zval* filter, Constructs a new Command */ static PHP_METHOD(Command, __construct) { - php_phongo_command_t* intern; zend_error_handling error_handling; + php_phongo_command_t* intern; zval* document; zval* options = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_COMMAND_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &document, &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 9b0035630..226440e3e 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -204,6 +204,7 @@ static zend_object_iterator* php_phongo_cursor_get_iterator(zend_class_entry* ce Sets a type map to use for BSON unserialization */ static PHP_METHOD(Cursor, setTypeMap) { + zend_error_handling error_handling; php_phongo_cursor_t* intern; php_phongo_bson_state state; zval* typemap = NULL; @@ -213,9 +214,12 @@ static PHP_METHOD(Cursor, setTypeMap) intern = Z_CURSOR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a!", &typemap) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_bson_typemap_to_state(typemap, &state.map)) { return; @@ -276,9 +280,14 @@ static void php_phongo_cursor_id_new_from_id(zval* object, int64_t cursorid) /* Returns an array of all result documents for this cursor */ static PHP_METHOD(Cursor, toArray) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init(return_value); @@ -292,13 +301,17 @@ static PHP_METHOD(Cursor, toArray) Returns the CursorId for this cursor */ static PHP_METHOD(Cursor, getId) { + zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_cursor_id_new_from_id(return_value, mongoc_cursor_get_id(intern->cursor)); } /* }}} */ @@ -307,13 +320,17 @@ static PHP_METHOD(Cursor, getId) Returns the Server object to which this cursor is attached */ static PHP_METHOD(Cursor, getServer) { + zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_server_init(return_value, intern->client, intern->server_id); } /* }}} */ @@ -322,13 +339,17 @@ static PHP_METHOD(Cursor, getServer) Checks if a cursor is still alive */ static PHP_METHOD(Cursor, isDead) { + zend_error_handling error_handling; php_phongo_cursor_t* intern; intern = Z_CURSOR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_BOOL(!mongoc_cursor_more(intern->cursor)); } /* }}} */ @@ -336,9 +357,14 @@ static PHP_METHOD(Cursor, isDead) #if PHP_VERSION_ID >= 80000 static PHP_METHOD(Cursor, getIterator) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); zend_create_internal_iterator_zval(return_value, getThis()); } diff --git a/src/MongoDB/CursorId.c b/src/MongoDB/CursorId.c index 448fb5e94..9342d57b5 100644 --- a/src/MongoDB/CursorId.c +++ b/src/MongoDB/CursorId.c @@ -61,15 +61,19 @@ static bool php_phongo_cursorid_init_from_hash(php_phongo_cursorid_t* intern, Ha Returns the string representation of the CursorId */ static PHP_METHOD(CursorId, __toString) { + zend_error_handling error_handling; php_phongo_cursorid_t* intern; char* tmp; int tmp_len; intern = Z_CURSORID_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); tmp_len = spprintf(&tmp, 0, "%" PRId64, intern->id); RETVAL_STRINGL(tmp, tmp_len); @@ -80,14 +84,18 @@ static PHP_METHOD(CursorId, __toString) */ static PHP_METHOD(CursorId, serialize) { + zend_error_handling error_handling; php_phongo_cursorid_t* intern; zval retval; php_serialize_data_t var_hash; smart_str buf = { 0 }; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_CURSORID_OBJ_P(getThis()); @@ -109,8 +117,8 @@ static PHP_METHOD(CursorId, serialize) */ static PHP_METHOD(CursorId, unserialize) { - php_phongo_cursorid_t* intern; zend_error_handling error_handling; + php_phongo_cursorid_t* intern; char* serialized; size_t serialized_len; zval props; @@ -119,7 +127,6 @@ static PHP_METHOD(CursorId, unserialize) intern = Z_CURSORID_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/Exception/CommandException.c b/src/MongoDB/Exception/CommandException.c index 47692e939..4345e386a 100644 --- a/src/MongoDB/Exception/CommandException.c +++ b/src/MongoDB/Exception/CommandException.c @@ -29,12 +29,16 @@ zend_class_entry* php_phongo_commandexception_ce; Returns the result document from the failed command. */ static PHP_METHOD(CommandException, getResultDocument) { - zval* resultdocument; - zval rv; + zend_error_handling error_handling; + zval* resultdocument; + zval rv; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); resultdocument = zend_read_property(php_phongo_commandexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("resultDocument"), 0, &rv); diff --git a/src/MongoDB/Exception/RuntimeException.c b/src/MongoDB/Exception/RuntimeException.c index 3f6e4cece..c99936a4c 100644 --- a/src/MongoDB/Exception/RuntimeException.c +++ b/src/MongoDB/Exception/RuntimeException.c @@ -56,14 +56,18 @@ static bool php_phongo_has_string_array_element(zval* labels, char* label) Returns whether a specific error label has been set */ static PHP_METHOD(RuntimeException, hasErrorLabel) { - char* label; - size_t label_len; - zval* error_labels; - zval rv; + zend_error_handling error_handling; + char* label; + size_t label_len; + zval* error_labels; + zval rv; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &label, &label_len) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); error_labels = zend_read_property(php_phongo_runtimeexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("errorLabels"), 0, &rv); diff --git a/src/MongoDB/Exception/WriteException.c b/src/MongoDB/Exception/WriteException.c index 869991da5..5a644306e 100644 --- a/src/MongoDB/Exception/WriteException.c +++ b/src/MongoDB/Exception/WriteException.c @@ -29,12 +29,16 @@ zend_class_entry* php_phongo_writeexception_ce; Returns the WriteResult from the failed write operation. */ static PHP_METHOD(WriteException, getWriteResult) { - zval* writeresult; - zval rv; + zend_error_handling error_handling; + zval* writeresult; + zval rv; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); writeresult = zend_read_property(php_phongo_writeexception_ce, PHONGO_COMPAT_OBJ_P(getThis()), ZEND_STRL("writeResult"), 0, &rv); diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 8a7fe6ef4..248e62da2 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -238,20 +238,19 @@ static bool php_phongo_manager_select_server(bool for_writes, bool inherit_read_ Constructs a new Manager */ static PHP_METHOD(Manager, __construct) { - php_phongo_manager_t* intern; zend_error_handling error_handling; + php_phongo_manager_t* intern; char* uri_string = NULL; size_t uri_string_len = 0; zval* options = NULL; zval* driverOptions = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - intern = Z_MANAGER_OBJ_P(getThis()); /* Separate the options and driverOptions zvals, since we may end up * modifying them in php_phongo_manager_prep_uri_options() and * php_phongo_manager_merge_context_options() below, respectively. */ + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!a/!a/!", &uri_string, &uri_string_len, &options, &driverOptions) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -278,13 +277,17 @@ static PHP_METHOD(Manager, __construct) Return a ClientEncryption instance */ static PHP_METHOD(Manager, createClientEncryption) { + zend_error_handling error_handling; php_phongo_manager_t* intern; php_phongo_clientencryption_t* clientencryption; zval* options; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -298,6 +301,7 @@ static PHP_METHOD(Manager, createClientEncryption) Execute a Command */ static PHP_METHOD(Manager, executeCommand) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -308,9 +312,12 @@ static PHP_METHOD(Manager, executeCommand) zval* zsession = NULL; uint32_t server_id = 0; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -348,6 +355,7 @@ static PHP_METHOD(Manager, executeCommand) Execute a ReadCommand */ static PHP_METHOD(Manager, executeReadCommand) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -357,9 +365,12 @@ static PHP_METHOD(Manager, executeReadCommand) uint32_t server_id = 0; zval* zsession = NULL; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -390,6 +401,7 @@ static PHP_METHOD(Manager, executeReadCommand) Execute a WriteCommand */ static PHP_METHOD(Manager, executeWriteCommand) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -398,9 +410,12 @@ static PHP_METHOD(Manager, executeWriteCommand) uint32_t server_id = 0; zval* zsession = NULL; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -426,6 +441,7 @@ static PHP_METHOD(Manager, executeWriteCommand) Execute a ReadWriteCommand */ static PHP_METHOD(Manager, executeReadWriteCommand) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* db; size_t db_len; @@ -434,9 +450,12 @@ static PHP_METHOD(Manager, executeReadWriteCommand) uint32_t server_id = 0; zval* zsession = NULL; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -462,6 +481,7 @@ static PHP_METHOD(Manager, executeReadWriteCommand) Execute a Query */ static PHP_METHOD(Manager, executeQuery) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* namespace; size_t namespace_len; @@ -472,9 +492,12 @@ static PHP_METHOD(Manager, executeQuery) uint32_t server_id = 0; zval* zsession = NULL; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &query, php_phongo_query_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); @@ -512,6 +535,7 @@ static PHP_METHOD(Manager, executeQuery) Executes a BulkWrite (i.e. any number of insert, update, and delete ops) */ static PHP_METHOD(Manager, executeBulkWrite) { + zend_error_handling error_handling; php_phongo_manager_t* intern; char* namespace; size_t namespace_len; @@ -522,9 +546,12 @@ static PHP_METHOD(Manager, executeBulkWrite) uint32_t server_id = 0; zval* zsession = NULL; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); intern = Z_MANAGER_OBJ_P(getThis()); bulk = Z_BULKWRITE_OBJ_P(zbulk); @@ -557,13 +584,17 @@ static PHP_METHOD(Manager, executeBulkWrite) Returns the ReadConcern associated with this Manager */ static PHP_METHOD(Manager, getReadConcern) { + zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_readconcern_init(return_value, mongoc_client_get_read_concern(intern->client)); } /* }}} */ @@ -572,13 +603,17 @@ static PHP_METHOD(Manager, getReadConcern) Returns the ReadPreference associated with this Manager */ static PHP_METHOD(Manager, getReadPreference) { + zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_readpreference_init(return_value, mongoc_client_get_read_prefs(intern->client)); } /* }}} */ @@ -587,15 +622,19 @@ static PHP_METHOD(Manager, getReadPreference) Returns the Servers associated with this Manager */ static PHP_METHOD(Manager, getServers) { + zend_error_handling error_handling; php_phongo_manager_t* intern; mongoc_server_description_t** sds; size_t i, n = 0; intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sds = mongoc_client_get_server_descriptions(intern->client, &n); array_init_size(return_value, n); @@ -614,13 +653,17 @@ static PHP_METHOD(Manager, getServers) Returns the WriteConcern associated with this Manager */ static PHP_METHOD(Manager, getWriteConcern) { + zend_error_handling error_handling; php_phongo_manager_t* intern; intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_writeconcern_init(return_value, mongoc_client_get_write_concern(intern->client)); } /* }}} */ @@ -629,15 +672,19 @@ static PHP_METHOD(Manager, getWriteConcern) Returns a suitable Server for the given ReadPreference */ static PHP_METHOD(Manager, selectServer) { + zend_error_handling error_handling; php_phongo_manager_t* intern; zval* zreadPreference = NULL; uint32_t server_id = 0; intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zreadPreference, php_phongo_readpreference_ce) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_manager_select_server(false, true, zreadPreference, NULL, intern->client, &server_id)) { /* Exception should already have been thrown */ @@ -651,6 +698,7 @@ static PHP_METHOD(Manager, selectServer) Returns a new client session */ static PHP_METHOD(Manager, startSession) { + zend_error_handling error_handling; php_phongo_manager_t* intern; zval* options = NULL; mongoc_session_opt_t* cs_opts = NULL; @@ -660,9 +708,12 @@ static PHP_METHOD(Manager, startSession) intern = Z_MANAGER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (options && php_array_existsc(options, "causalConsistency")) { cs_opts = mongoc_session_opts_new(); diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index ee1d306af..487aac353 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -30,13 +30,17 @@ zend_class_entry* php_phongo_commandfailedevent_ce; Returns the command name for this event */ PHP_METHOD(CommandFailedEvent, getCommandName) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -45,13 +49,17 @@ PHP_METHOD(CommandFailedEvent, getCommandName) Returns the event's duration in microseconds */ PHP_METHOD(CommandFailedEvent, getDurationMicros) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->duration_micros); } /* }}} */ @@ -60,13 +68,17 @@ PHP_METHOD(CommandFailedEvent, getDurationMicros) Returns the error document associated with the event */ PHP_METHOD(CommandFailedEvent, getError) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_ZVAL(&intern->z_error, 1, 0); } /* }}} */ @@ -75,14 +87,18 @@ PHP_METHOD(CommandFailedEvent, getError) Returns the event's operation ID */ PHP_METHOD(CommandFailedEvent, getOperationId) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -92,6 +108,7 @@ PHP_METHOD(CommandFailedEvent, getOperationId) Returns the reply document associated with the event */ PHP_METHOD(CommandFailedEvent, getReply) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; php_phongo_bson_state state; @@ -99,9 +116,12 @@ PHP_METHOD(CommandFailedEvent, getReply) intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -115,14 +135,18 @@ PHP_METHOD(CommandFailedEvent, getReply) Returns the event's request ID */ PHP_METHOD(CommandFailedEvent, getRequestId) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -132,13 +156,17 @@ PHP_METHOD(CommandFailedEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandFailedEvent, getServer) { + zend_error_handling error_handling; php_phongo_commandfailedevent_t* intern; intern = Z_COMMANDFAILEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_server_init(return_value, intern->client, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index 476d73eca..3084af3e8 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -30,6 +30,7 @@ zend_class_entry* php_phongo_commandstartedevent_ce; Returns the command document associated with the event */ PHP_METHOD(CommandStartedEvent, getCommand) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; php_phongo_bson_state state; @@ -37,9 +38,12 @@ PHP_METHOD(CommandStartedEvent, getCommand) intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->command), intern->command->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -53,13 +57,17 @@ PHP_METHOD(CommandStartedEvent, getCommand) Returns the command name for this event */ PHP_METHOD(CommandStartedEvent, getCommandName) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -68,13 +76,17 @@ PHP_METHOD(CommandStartedEvent, getCommandName) Returns the database name for this event */ PHP_METHOD(CommandStartedEvent, getDatabaseName) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_STRING(intern->database_name); } /* }}} */ @@ -83,14 +95,18 @@ PHP_METHOD(CommandStartedEvent, getDatabaseName) Returns the event's operation ID */ PHP_METHOD(CommandStartedEvent, getOperationId) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -100,14 +116,18 @@ PHP_METHOD(CommandStartedEvent, getOperationId) Returns the event's request ID */ PHP_METHOD(CommandStartedEvent, getRequestId) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -117,13 +137,17 @@ PHP_METHOD(CommandStartedEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandStartedEvent, getServer) { + zend_error_handling error_handling; php_phongo_commandstartedevent_t* intern; intern = Z_COMMANDSTARTEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_server_init(return_value, intern->client, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index 304aeb307..622e156ca 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -30,13 +30,17 @@ zend_class_entry* php_phongo_commandsucceededevent_ce; Returns the command name for this event */ PHP_METHOD(CommandSucceededEvent, getCommandName) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETVAL_STRING(intern->command_name); } /* }}} */ @@ -45,13 +49,17 @@ PHP_METHOD(CommandSucceededEvent, getCommandName) Returns the event's duration in microseconds */ PHP_METHOD(CommandSucceededEvent, getDurationMicros) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->duration_micros); } /* }}} */ @@ -60,14 +68,18 @@ PHP_METHOD(CommandSucceededEvent, getDurationMicros) Returns the event's operation ID */ PHP_METHOD(CommandSucceededEvent, getOperationId) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->operation_id); RETVAL_STRING(int_as_string); @@ -77,6 +89,7 @@ PHP_METHOD(CommandSucceededEvent, getOperationId) Returns the reply document associated with the event */ PHP_METHOD(CommandSucceededEvent, getReply) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; php_phongo_bson_state state; @@ -84,9 +97,12 @@ PHP_METHOD(CommandSucceededEvent, getReply) intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_bson_to_zval_ex(bson_get_data(intern->reply), intern->reply->len, &state)) { zval_ptr_dtor(&state.zchild); @@ -100,14 +116,18 @@ PHP_METHOD(CommandSucceededEvent, getReply) Returns the event's request ID */ PHP_METHOD(CommandSucceededEvent, getRequestId) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; char int_as_string[20]; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); sprintf(int_as_string, "%" PRIu64, intern->request_id); RETVAL_STRING(int_as_string); @@ -117,13 +137,17 @@ PHP_METHOD(CommandSucceededEvent, getRequestId) Returns the Server from which the event originated */ PHP_METHOD(CommandSucceededEvent, getServer) { + zend_error_handling error_handling; php_phongo_commandsucceededevent_t* intern; intern = Z_COMMANDSUCCEEDEDEVENT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_server_init(return_value, intern->client, intern->server_id); } /* }}} */ diff --git a/src/MongoDB/Monitoring/functions.c b/src/MongoDB/Monitoring/functions.c index d5ea791a6..bdb722173 100644 --- a/src/MongoDB/Monitoring/functions.c +++ b/src/MongoDB/Monitoring/functions.c @@ -39,13 +39,17 @@ static char* php_phongo_make_subscriber_hash(zval* subscriber) Adds a monitoring subscriber to the set of subscribers */ PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber) { - zval* zSubscriber = NULL; - char* hash; - zval* subscriber; + zend_error_handling error_handling; + zval* zSubscriber = NULL; + char* hash; + zval* subscriber; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zSubscriber, php_phongo_subscriber_ce) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); /* The HashTable should never be NULL, as it's initialized during RINIT and * destroyed during RSHUTDOWN. This is simply a defensive guard. */ @@ -71,12 +75,16 @@ PHP_FUNCTION(MongoDB_Driver_Monitoring_addSubscriber) Removes a monitoring subscriber from the set of subscribers */ PHP_FUNCTION(MongoDB_Driver_Monitoring_removeSubscriber) { - zval* zSubscriber = NULL; - char* hash; + zend_error_handling error_handling; + zval* zSubscriber = NULL; + char* hash; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &zSubscriber, php_phongo_subscriber_ce) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); /* The HashTable should never be NULL, as it's initialized during RINIT and * destroyed during RSHUTDOWN. This is simply a defensive guard. */ diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index b006e2848..fde9d775f 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -352,14 +352,14 @@ static bool php_phongo_query_init(php_phongo_query_t* intern, zval* filter, zval Constructs a new Query */ static PHP_METHOD(Query, __construct) { - php_phongo_query_t* intern; zend_error_handling error_handling; + php_phongo_query_t* intern; zval* filter; zval* options = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_QUERY_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A|a!", &filter, &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 68448337e..fe8cafbf0 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -58,14 +58,14 @@ static bool php_phongo_readconcern_init_from_hash(php_phongo_readconcern_t* inte Constructs a new ReadConcern */ static PHP_METHOD(ReadConcern, __construct) { - php_phongo_readconcern_t* intern; zend_error_handling error_handling; + php_phongo_readconcern_t* intern; char* level = NULL; size_t level_len = 0; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_READCONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &level, &level_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -83,13 +83,17 @@ static PHP_METHOD(ReadConcern, __construct) */ static PHP_METHOD(ReadConcern, __set_state) { + zend_error_handling error_handling; php_phongo_readconcern_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_readconcern_ce); @@ -103,14 +107,18 @@ static PHP_METHOD(ReadConcern, __set_state) Returns the ReadConcern "level" option */ static PHP_METHOD(ReadConcern, getLevel) { + zend_error_handling error_handling; php_phongo_readconcern_t* intern; const char* level; intern = Z_READCONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); level = mongoc_read_concern_get_level(intern->read_concern); @@ -126,13 +134,17 @@ static PHP_METHOD(ReadConcern, getLevel) without a level or from a Manager with no read concern URI options). */ static PHP_METHOD(ReadConcern, isDefault) { + zend_error_handling error_handling; php_phongo_readconcern_t* intern; intern = Z_READCONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern)); } /* }}} */ @@ -167,9 +179,14 @@ static HashTable* php_phongo_read_concern_get_properties_hash(phongo_compat_obje */ static PHP_METHOD(ReadConcern, bsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); ZVAL_ARR(return_value, php_phongo_read_concern_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true)); convert_to_object(return_value); @@ -179,6 +196,7 @@ static PHP_METHOD(ReadConcern, bsonSerialize) */ static PHP_METHOD(ReadConcern, serialize) { + zend_error_handling error_handling; php_phongo_readconcern_t* intern; zval retval; php_serialize_data_t var_hash; @@ -187,9 +205,12 @@ static PHP_METHOD(ReadConcern, serialize) intern = Z_READCONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!intern->read_concern) { return; @@ -219,8 +240,8 @@ static PHP_METHOD(ReadConcern, serialize) */ static PHP_METHOD(ReadConcern, unserialize) { - php_phongo_readconcern_t* intern; zend_error_handling error_handling; + php_phongo_readconcern_t* intern; char* serialized; size_t serialized_len; zval props; @@ -229,7 +250,6 @@ static PHP_METHOD(ReadConcern, unserialize) intern = Z_READCONCERN_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 5bd707d85..3c0996661 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -177,17 +177,17 @@ static const char* php_phongo_readpreference_get_mode_string(mongoc_read_mode_t Constructs a new ReadPreference */ static PHP_METHOD(ReadPreference, __construct) { - php_phongo_readpreference_t* intern; zend_error_handling error_handling; + php_phongo_readpreference_t* intern; zval* mode; zval* tagSets = NULL; zval* options = NULL; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_READPREFERENCE_OBJ_P(getThis()); /* Separate the tagSets zval, since we may end up modifying it in * php_phongo_read_preference_prep_tagsets() below. */ + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|a/!a!", &mode, &tagSets, &options) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -307,6 +307,7 @@ static PHP_METHOD(ReadPreference, __construct) */ static PHP_METHOD(ReadPreference, __set_state) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; HashTable* props; zval* array; @@ -314,9 +315,12 @@ static PHP_METHOD(ReadPreference, __set_state) /* Separate the zval, since we may end up modifying the "tags" element in * php_phongo_read_preference_prep_tagsets(), which is called from * php_phongo_readpreference_init_from_hash. */ + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a/", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_readpreference_ce); @@ -330,14 +334,18 @@ static PHP_METHOD(ReadPreference, __set_state) Returns the ReadPreference hedge document */ static PHP_METHOD(ReadPreference, getHedge) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; const bson_t* hedge; intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); hedge = mongoc_read_prefs_get_hedge(intern->read_preference); @@ -361,13 +369,17 @@ static PHP_METHOD(ReadPreference, getHedge) Returns the ReadPreference maxStalenessSeconds value */ static PHP_METHOD(ReadPreference, getMaxStalenessSeconds) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(mongoc_read_prefs_get_max_staleness_seconds(intern->read_preference)); } /* }}} */ @@ -376,13 +388,17 @@ static PHP_METHOD(ReadPreference, getMaxStalenessSeconds) Returns the ReadPreference mode */ static PHP_METHOD(ReadPreference, getMode) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(mongoc_read_prefs_get_mode(intern->read_preference)); } /* }}} */ @@ -391,14 +407,18 @@ static PHP_METHOD(ReadPreference, getMode) Returns the ReadPreference mode as string */ static PHP_METHOD(ReadPreference, getModeString) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; const char* mode_string; intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); mode_string = php_phongo_readpreference_get_mode_string(mongoc_read_prefs_get_mode(intern->read_preference)); if (!mode_string) { @@ -413,14 +433,18 @@ static PHP_METHOD(ReadPreference, getModeString) Returns the ReadPreference tag sets */ static PHP_METHOD(ReadPreference, getTagSets) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; const bson_t* tags; intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -514,9 +538,14 @@ static HashTable* php_phongo_readpreference_get_properties_hash(phongo_compat_ob */ static PHP_METHOD(ReadPreference, bsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true)); convert_to_object(return_value); @@ -526,6 +555,7 @@ static PHP_METHOD(ReadPreference, bsonSerialize) */ static PHP_METHOD(ReadPreference, serialize) { + zend_error_handling error_handling; php_phongo_readpreference_t* intern; zval retval; php_serialize_data_t var_hash; @@ -538,9 +568,12 @@ static PHP_METHOD(ReadPreference, serialize) intern = Z_READPREFERENCE_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!intern->read_preference) { return; @@ -603,8 +636,8 @@ static PHP_METHOD(ReadPreference, serialize) */ static PHP_METHOD(ReadPreference, unserialize) { - php_phongo_readpreference_t* intern; zend_error_handling error_handling; + php_phongo_readpreference_t* intern; char* serialized; size_t serialized_len; zval props; @@ -613,7 +646,6 @@ static PHP_METHOD(ReadPreference, unserialize) intern = Z_READPREFERENCE_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/Server.c b/src/MongoDB/Server.c index e2996fc2d..76714e692 100644 --- a/src/MongoDB/Server.c +++ b/src/MongoDB/Server.c @@ -31,6 +31,7 @@ zend_class_entry* php_phongo_server_ce; Executes a Command on this Server */ static PHP_METHOD(Server, executeCommand) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -40,9 +41,12 @@ static PHP_METHOD(Server, executeCommand) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); options = php_phongo_prep_legacy_option(options, "readPreference", &free_options); @@ -62,6 +66,7 @@ static PHP_METHOD(Server, executeCommand) Executes a ReadCommand on this Server */ static PHP_METHOD(Server, executeReadCommand) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -70,9 +75,12 @@ static PHP_METHOD(Server, executeReadCommand) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated and its @@ -86,6 +94,7 @@ static PHP_METHOD(Server, executeReadCommand) Executes a WriteCommand on this Server */ static PHP_METHOD(Server, executeWriteCommand) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -94,9 +103,12 @@ static PHP_METHOD(Server, executeWriteCommand) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated. and its @@ -110,6 +122,7 @@ static PHP_METHOD(Server, executeWriteCommand) Executes a ReadWriteCommand on this Server */ static PHP_METHOD(Server, executeReadWriteCommand) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* db; size_t db_len; @@ -118,9 +131,12 @@ static PHP_METHOD(Server, executeReadWriteCommand) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|a!", &db, &db_len, &command, php_phongo_command_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); /* If the Server was created in a different process, reset the client so * that cursors created by this process can be differentiated and its @@ -134,6 +150,7 @@ static PHP_METHOD(Server, executeReadWriteCommand) Executes a Query on this Server */ static PHP_METHOD(Server, executeQuery) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* namespace; size_t namespace_len; @@ -143,9 +160,12 @@ static PHP_METHOD(Server, executeQuery) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &query, php_phongo_query_ce, &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); options = php_phongo_prep_legacy_option(options, "readPreference", &free_options); @@ -166,6 +186,7 @@ static PHP_METHOD(Server, executeQuery) this Server */ static PHP_METHOD(Server, executeBulkWrite) { + zend_error_handling error_handling; php_phongo_server_t* intern; char* namespace; size_t namespace_len; @@ -176,9 +197,12 @@ static PHP_METHOD(Server, executeBulkWrite) intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "sO|z!", &namespace, &namespace_len, &zbulk, php_phongo_bulkwrite_ce, &options, php_phongo_writeconcern_ce) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); bulk = Z_BULKWRITE_OBJ_P(zbulk); @@ -199,14 +223,18 @@ static PHP_METHOD(Server, executeBulkWrite) Returns the hostname for this Server */ static PHP_METHOD(Server, getHost) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_STRING(mongoc_server_description_host(sd)->host); @@ -221,14 +249,18 @@ static PHP_METHOD(Server, getHost) Returns the currently configured tags for this Server */ static PHP_METHOD(Server, getTags) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { const bson_t* is_master = mongoc_server_description_ismaster(sd); @@ -266,14 +298,18 @@ static PHP_METHOD(Server, getTags) Returns the last isMaster result document for this Server */ static PHP_METHOD(Server, getInfo) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { const bson_t* is_master = mongoc_server_description_ismaster(sd); @@ -300,14 +336,18 @@ static PHP_METHOD(Server, getInfo) Returns the last measured latency for this Server */ static PHP_METHOD(Server, getLatency) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_LONG((zend_long) mongoc_server_description_round_trip_time(sd)); @@ -322,14 +362,18 @@ static PHP_METHOD(Server, getLatency) Returns the port for this Server */ static PHP_METHOD(Server, getPort) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_LONG(mongoc_server_description_host(sd)->port); @@ -344,14 +388,18 @@ static PHP_METHOD(Server, getPort) Returns the node type of this Server */ static PHP_METHOD(Server, getType) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_LONG(php_phongo_server_description_type(sd)); @@ -366,14 +414,18 @@ static PHP_METHOD(Server, getType) Returns whether this Server is a primary member of a replica set */ static PHP_METHOD(Server, isPrimary) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_PRIMARY].name)); @@ -388,14 +440,18 @@ static PHP_METHOD(Server, isPrimary) Returns whether this Server is a secondary member of a replica set */ static PHP_METHOD(Server, isSecondary) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_SECONDARY].name)); @@ -410,14 +466,18 @@ static PHP_METHOD(Server, isSecondary) Returns whether this Server is an arbiter member of a replica set */ static PHP_METHOD(Server, isArbiter) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { RETVAL_BOOL(!strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_RS_ARBITER].name)); @@ -432,14 +492,18 @@ static PHP_METHOD(Server, isArbiter) Returns whether this Server is a hidden member of a replica set */ static PHP_METHOD(Server, isHidden) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { bson_iter_t iter; @@ -456,14 +520,18 @@ static PHP_METHOD(Server, isHidden) Returns whether this Server is a passive member of a replica set */ static PHP_METHOD(Server, isPassive) { + zend_error_handling error_handling; php_phongo_server_t* intern; mongoc_server_description_t* sd; intern = Z_SERVER_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if ((sd = mongoc_client_get_server_description(intern->client, intern->server_id))) { bson_iter_t iter; diff --git a/src/MongoDB/Session.c b/src/MongoDB/Session.c index 7130ef531..cf0741711 100644 --- a/src/MongoDB/Session.c +++ b/src/MongoDB/Session.c @@ -102,6 +102,7 @@ static const char* php_phongo_get_transaction_state_string(mongoc_transaction_st Advances the cluster time for this Session */ static PHP_METHOD(Session, advanceClusterTime) { + zend_error_handling error_handling; php_phongo_session_t* intern; zval* zcluster_time; bson_t cluster_time = BSON_INITIALIZER; @@ -109,9 +110,12 @@ static PHP_METHOD(Session, advanceClusterTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "advanceClusterTime") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "A", &zcluster_time) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_zval_to_bson(zcluster_time, PHONGO_BSON_NONE, &cluster_time, NULL); @@ -130,6 +134,7 @@ static PHP_METHOD(Session, advanceClusterTime) Advances the operation time for this Session */ static PHP_METHOD(Session, advanceOperationTime) { + zend_error_handling error_handling; php_phongo_session_t* intern; zval* ztimestamp; uint32_t timestamp = 0; @@ -138,9 +143,12 @@ static PHP_METHOD(Session, advanceOperationTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "advanceOperationTime") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &ztimestamp, php_phongo_timestamp_interface_ce) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!php_phongo_session_get_timestamp_parts(ztimestamp, ×tamp, &increment)) { return; @@ -153,6 +161,7 @@ static PHP_METHOD(Session, advanceOperationTime) Returns the cluster time for this Session */ static PHP_METHOD(Session, getClusterTime) { + zend_error_handling error_handling; php_phongo_session_t* intern; const bson_t* cluster_time; php_phongo_bson_state state; @@ -162,9 +171,12 @@ static PHP_METHOD(Session, getClusterTime) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getClusterTime") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); cluster_time = mongoc_client_session_get_cluster_time(intern->client_session); @@ -185,6 +197,7 @@ static PHP_METHOD(Session, getClusterTime) Returns the logical session ID for this Session */ static PHP_METHOD(Session, getLogicalSessionId) { + zend_error_handling error_handling; php_phongo_session_t* intern; const bson_t* lsid; php_phongo_bson_state state; @@ -194,9 +207,12 @@ static PHP_METHOD(Session, getLogicalSessionId) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getLogicalSessionId") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); lsid = mongoc_client_session_get_lsid(intern->client_session); @@ -213,15 +229,19 @@ static PHP_METHOD(Session, getLogicalSessionId) Returns the operation time for this Session */ static PHP_METHOD(Session, getOperationTime) { + zend_error_handling error_handling; php_phongo_session_t* intern; uint32_t timestamp, increment; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getOperationTime") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); mongoc_client_session_get_operation_time(intern->client_session, ×tamp, &increment); @@ -239,15 +259,19 @@ static PHP_METHOD(Session, getOperationTime) Returns the server this session is pinned to */ static PHP_METHOD(Session, getServer) { + zend_error_handling error_handling; php_phongo_session_t* intern; uint32_t server_id = 0; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getServer") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); server_id = mongoc_client_session_get_server_id(intern->client_session); @@ -263,6 +287,7 @@ static PHP_METHOD(Session, getServer) Returns options for the currently running transaction */ static PHP_METHOD(Session, getTransactionOptions) { + zend_error_handling error_handling; php_phongo_session_t* intern; mongoc_transaction_opt_t* opts; int64_t max_commit_time_ms; @@ -273,9 +298,12 @@ static PHP_METHOD(Session, getTransactionOptions) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getTransactionOptions") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); opts = mongoc_session_opts_get_transaction_opts(intern->client_session); @@ -320,15 +348,19 @@ static PHP_METHOD(Session, getTransactionOptions) Returns the current transaction state for this session */ static PHP_METHOD(Session, getTransactionState) { + zend_error_handling error_handling; php_phongo_session_t* intern; const char* state; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "getTransactionState") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); state = php_phongo_get_transaction_state_string(mongoc_client_session_get_transaction_state(intern->client_session)); if (!state) { @@ -440,6 +472,7 @@ mongoc_transaction_opt_t* php_mongodb_session_parse_transaction_options(zval* op Starts a new transaction */ static PHP_METHOD(Session, startTransaction) { + zend_error_handling error_handling; php_phongo_session_t* intern; zval* options = NULL; mongoc_transaction_opt_t* txn_options = NULL; @@ -448,9 +481,12 @@ static PHP_METHOD(Session, startTransaction) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "startTransaction") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a!", &options) == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (options) { txn_options = php_mongodb_session_parse_transaction_options(options); @@ -472,6 +508,7 @@ static PHP_METHOD(Session, startTransaction) Commits an existing transaction */ static PHP_METHOD(Session, commitTransaction) { + zend_error_handling error_handling; php_phongo_session_t* intern; bson_error_t error; bson_t reply; @@ -479,9 +516,12 @@ static PHP_METHOD(Session, commitTransaction) intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "commitTransaction") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!mongoc_client_session_commit_transaction(intern->client_session, &reply, &error)) { phongo_throw_exception_from_bson_error_t_and_reply(&error, &reply); @@ -494,15 +534,19 @@ static PHP_METHOD(Session, commitTransaction) Aborts (rolls back) an existing transaction */ static PHP_METHOD(Session, abortTransaction) { + zend_error_handling error_handling; php_phongo_session_t* intern; bson_error_t error; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "abortTransaction") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!mongoc_client_session_abort_transaction(intern->client_session, &error)) { phongo_throw_exception_from_bson_error_t(&error); @@ -513,13 +557,17 @@ static PHP_METHOD(Session, abortTransaction) Ends the session, and a running transaction if active */ static PHP_METHOD(Session, endSession) { + zend_error_handling error_handling; php_phongo_session_t* intern; intern = Z_SESSION_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); mongoc_client_session_destroy(intern->client_session); intern->client_session = NULL; @@ -529,14 +577,18 @@ static PHP_METHOD(Session, endSession) Returns whether a multi-document transaction is in progress */ static PHP_METHOD(Session, isInTransaction) { + zend_error_handling error_handling; php_phongo_session_t* intern; intern = Z_SESSION_OBJ_P(getThis()); SESSION_CHECK_LIVELINESS(intern, "isInTransaction") + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_BOOL(mongoc_client_session_in_transaction(intern->client_session)); } /* }}} */ diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index a50a066e0..4e206e9ee 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -109,14 +109,14 @@ static bool php_phongo_writeconcern_init_from_hash(php_phongo_writeconcern_t* in Constructs a new WriteConcern */ static PHP_METHOD(WriteConcern, __construct) { - php_phongo_writeconcern_t* intern; zend_error_handling error_handling; + php_phongo_writeconcern_t* intern; zval * w, *journal; zend_long wtimeout = 0; - zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|lz", &w, &wtimeout, &journal) == FAILURE) { zend_restore_error_handling(&error_handling); return; @@ -172,13 +172,17 @@ static PHP_METHOD(WriteConcern, __construct) */ static PHP_METHOD(WriteConcern, __set_state) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; HashTable* props; zval* array; + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters(ZEND_NUM_ARGS(), "a", &array) == FAILURE) { - RETURN_FALSE; + zend_restore_error_handling(&error_handling); + return; } + zend_restore_error_handling(&error_handling); object_init_ex(return_value, php_phongo_writeconcern_ce); @@ -192,14 +196,18 @@ static PHP_METHOD(WriteConcern, __set_state) Returns the WriteConcern "w" option */ static PHP_METHOD(WriteConcern, getW) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; const char* wtag; intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -222,14 +230,18 @@ static PHP_METHOD(WriteConcern, getW) Returns the WriteConcern "wtimeout" option */ static PHP_METHOD(WriteConcern, getWtimeout) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; int64_t wtimeout; intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); wtimeout = mongoc_write_concern_get_wtimeout_int64(intern->write_concern); @@ -246,13 +258,17 @@ static PHP_METHOD(WriteConcern, getWtimeout) Returns the WriteConcern "journal" option */ static PHP_METHOD(WriteConcern, getJournal) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (mongoc_write_concern_journal_is_set(intern->write_concern)) { RETURN_BOOL(mongoc_write_concern_get_journal(intern->write_concern)); @@ -266,13 +282,17 @@ static PHP_METHOD(WriteConcern, getJournal) with no write concern URI options). */ static PHP_METHOD(WriteConcern, isDefault) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern)); } /* }}} */ @@ -346,9 +366,14 @@ static HashTable* php_phongo_write_concern_get_properties_hash(phongo_compat_obj */ static PHP_METHOD(WriteConcern, bsonSerialize) { + zend_error_handling error_handling; + + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); ZVAL_ARR(return_value, php_phongo_write_concern_get_properties_hash(PHONGO_COMPAT_OBJ_P(getThis()), true, true)); convert_to_object(return_value); @@ -358,6 +383,7 @@ static PHP_METHOD(WriteConcern, bsonSerialize) */ static PHP_METHOD(WriteConcern, serialize) { + zend_error_handling error_handling; php_phongo_writeconcern_t* intern; zval retval; php_serialize_data_t var_hash; @@ -368,9 +394,12 @@ static PHP_METHOD(WriteConcern, serialize) intern = Z_WRITECONCERN_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!intern->write_concern) { return; @@ -417,8 +446,8 @@ static PHP_METHOD(WriteConcern, serialize) */ static PHP_METHOD(WriteConcern, unserialize) { - php_phongo_writeconcern_t* intern; zend_error_handling error_handling; + php_phongo_writeconcern_t* intern; char* serialized; size_t serialized_len; zval props; @@ -427,7 +456,6 @@ static PHP_METHOD(WriteConcern, unserialize) intern = Z_WRITECONCERN_OBJ_P(getThis()); zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &serialized, &serialized_len) == FAILURE) { zend_restore_error_handling(&error_handling); return; diff --git a/src/MongoDB/WriteConcernError.c b/src/MongoDB/WriteConcernError.c index ffedaaf9e..52adc56a3 100644 --- a/src/MongoDB/WriteConcernError.c +++ b/src/MongoDB/WriteConcernError.c @@ -30,13 +30,17 @@ zend_class_entry* php_phongo_writeconcernerror_ce; Returns the MongoDB error code */ static PHP_METHOD(WriteConcernError, getCode) { + zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->code); } /* }}} */ @@ -45,13 +49,17 @@ static PHP_METHOD(WriteConcernError, getCode) Returns additional metadata for the error */ static PHP_METHOD(WriteConcernError, getInfo) { + zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!Z_ISUNDEF(intern->info)) { RETURN_ZVAL(&intern->info, 1, 0); @@ -62,13 +70,17 @@ static PHP_METHOD(WriteConcernError, getInfo) Returns the actual error message from the server */ static PHP_METHOD(WriteConcernError, getMessage) { + zend_error_handling error_handling; php_phongo_writeconcernerror_t* intern; intern = Z_WRITECONCERNERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRING(intern->message); } /* }}} */ diff --git a/src/MongoDB/WriteError.c b/src/MongoDB/WriteError.c index 395adc749..b91916728 100644 --- a/src/MongoDB/WriteError.c +++ b/src/MongoDB/WriteError.c @@ -30,13 +30,17 @@ zend_class_entry* php_phongo_writeerror_ce; Returns the MongoDB error code */ static PHP_METHOD(WriteError, getCode) { + zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->code); } /* }}} */ @@ -46,13 +50,17 @@ static PHP_METHOD(WriteError, getCode) corresponds. */ static PHP_METHOD(WriteError, getIndex) { + zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_LONG(intern->index); } /* }}} */ @@ -61,13 +69,17 @@ static PHP_METHOD(WriteError, getIndex) Returns the actual error message from the server */ static PHP_METHOD(WriteError, getMessage) { + zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_STRING(intern->message); } /* }}} */ @@ -76,13 +88,17 @@ static PHP_METHOD(WriteError, getMessage) Returns additional metadata for the error */ static PHP_METHOD(WriteError, getInfo) { + zend_error_handling error_handling; php_phongo_writeerror_t* intern; intern = Z_WRITEERROR_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); if (!Z_ISUNDEF(intern->info)) { RETURN_ZVAL(&intern->info, 1, 0); diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index 1b2fe052d..111508f1b 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -109,14 +109,18 @@ static bool php_phongo_writeresult_get_writeerrors(php_phongo_writeresult_t* int Returns the number of documents that were inserted */ static PHP_METHOD(WriteResult, getInsertedCount) { + zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nInserted"); } /* }}} */ @@ -125,14 +129,18 @@ static PHP_METHOD(WriteResult, getInsertedCount) Returns the number of documents that matched the update criteria */ static PHP_METHOD(WriteResult, getMatchedCount) { + zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nMatched"); } /* }}} */ @@ -141,14 +149,18 @@ static PHP_METHOD(WriteResult, getMatchedCount) Returns the number of documents that were actually modified by an update */ static PHP_METHOD(WriteResult, getModifiedCount) { + zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nModified"); } /* }}} */ @@ -157,14 +169,18 @@ static PHP_METHOD(WriteResult, getModifiedCount) Returns the number of documents that were deleted */ static PHP_METHOD(WriteResult, getDeletedCount) { + zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nRemoved"); } /* }}} */ @@ -173,14 +189,18 @@ static PHP_METHOD(WriteResult, getDeletedCount) Returns the number of documents that were upserted */ static PHP_METHOD(WriteResult, getUpsertedCount) { + zend_error_handling error_handling; bson_iter_t iter; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); PHONGO_WRITERESULT_RETURN_LONG_FROM_BSON_INT32(&iter, intern->reply, "nUpserted"); } /* }}} */ @@ -189,13 +209,17 @@ static PHP_METHOD(WriteResult, getUpsertedCount) Returns the Server from which the result originated */ static PHP_METHOD(WriteResult, getServer) { + zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); phongo_server_init(return_value, intern->client, intern->server_id); } /* }}} */ @@ -204,14 +228,18 @@ static PHP_METHOD(WriteResult, getServer) Returns the identifiers generated by the server for upsert operations. */ static PHP_METHOD(WriteResult, getUpsertedIds) { + zend_error_handling error_handling; bson_iter_t iter, child; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); array_init(return_value); @@ -247,13 +275,17 @@ static PHP_METHOD(WriteResult, getUpsertedIds) Return any write concern error that occurred */ static PHP_METHOD(WriteResult, getWriteConcernError) { + zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_writeresult_get_writeconcernerror(intern, return_value); } /* }}} */ @@ -262,13 +294,17 @@ static PHP_METHOD(WriteResult, getWriteConcernError) Returns any write errors that occurred */ static PHP_METHOD(WriteResult, getWriteErrors) { + zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); php_phongo_writeresult_get_writeerrors(intern, return_value); } /* }}} */ @@ -278,13 +314,17 @@ static PHP_METHOD(WriteResult, getWriteErrors) concern). */ static PHP_METHOD(WriteResult, isAcknowledged) { + zend_error_handling error_handling; php_phongo_writeresult_t* intern; intern = Z_WRITERESULT_OBJ_P(getThis()); + zend_replace_error_handling(EH_THROW, phongo_exception_from_phongo_domain(PHONGO_ERROR_INVALID_ARGUMENT), &error_handling); if (zend_parse_parameters_none() == FAILURE) { + zend_restore_error_handling(&error_handling); return; } + zend_restore_error_handling(&error_handling); RETURN_BOOL(mongoc_write_concern_is_acknowledged(intern->write_concern)); } /* }}} */ diff --git a/tests/bson/bson-binary_error-001.phpt b/tests/bson/bson-binary_error-001.phpt index 66863093e..c44224f48 100644 --- a/tests/bson/bson-binary_error-001.phpt +++ b/tests/bson/bson-binary_error-001.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\BSON\Binary #001 error +MongoDB\BSON\Binary argument count errors --SKIPIF-- =', '7.99'); ?> @@ -9,20 +9,28 @@ MongoDB\BSON\Binary #001 error require_once __DIR__ . '/../utils/tools.php'; $binary = new MongoDB\BSON\Binary("random binary data", MongoDB\BSON\Binary::TYPE_GENERIC); -$binary->getData(2); -$binary->getType(2); -throws(function() { +echo throws(function() use ($binary) { + $binary->getData(2); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +echo throws(function() use ($binary) { + $binary->getType(2); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +echo throws(function() { new MongoDB\BSON\Binary("random binary data without type"); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== --EXPECTF-- -Warning: MongoDB\BSON\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d - -Warning: MongoDB\BSON\Binary::getType() expects exactly 0 parameters, 1 given in %s on line %d OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Binary::getData() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Binary::getType() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Binary::__construct() expects exactly 2 %r(argument|parameter)%rs, 1 given ===DONE=== diff --git a/tests/bson/bson-decimal128_error-001.phpt b/tests/bson/bson-decimal128_error-001.phpt index 1c44b8f72..27370de72 100644 --- a/tests/bson/bson-decimal128_error-001.phpt +++ b/tests/bson/bson-decimal128_error-001.phpt @@ -11,12 +11,18 @@ require_once __DIR__ . '/../utils/tools.php'; echo throws(function() { new MongoDB\BSON\Decimal128([]); -}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +echo throws(function() { + new MongoDB\BSON\Decimal128('foo'); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +%SMongoDB\BSON\Decimal128::__construct()%sstring, array given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\BSON\Decimal128::__construct() expects parameter 1 to be string, array given +Error parsing Decimal128 string: foo ===DONE=== diff --git a/tests/bson/bson-javascript_error-001.phpt b/tests/bson/bson-javascript_error-001.phpt index 0e27c9717..9cf0317c3 100644 --- a/tests/bson/bson-javascript_error-001.phpt +++ b/tests/bson/bson-javascript_error-001.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\BSON\Javascript #001 error +MongoDB\BSON\Javascript argument count errors --SKIPIF-- =', '7.99'); ?> @@ -8,13 +8,14 @@ MongoDB\BSON\Javascript #001 error require_once __DIR__ . '/../utils/tools.php'; -throws(function() { +echo throws(function() { new MongoDB\BSON\Javascript; -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Javascript::__construct() expects at least 1 %r(argument|parameter)%r, 0 given ===DONE=== diff --git a/tests/bson/bson-objectid-001.phpt b/tests/bson/bson-objectid-001.phpt index f2b81cba9..822b7162f 100644 --- a/tests/bson/bson-objectid-001.phpt +++ b/tests/bson/bson-objectid-001.phpt @@ -1,5 +1,8 @@ --TEST-- MongoDB\BSON\ObjectId #001 +--SKIPIF-- + +=', '7.99'); ?> --FILE-- $test) { throws(function() { $id = new MongoDB\BSON\ObjectId("53e28b650640fd3162152de12"); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class); throws(function() { $id = new MongoDB\BSON\ObjectId("53e28b650640fd3162152dg1"); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class); throws(function() { $id = new MongoDB\BSON\ObjectId("-3e28b650640fd3162152da1"); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class); throws(function() { $id = new MongoDB\BSON\ObjectId(" 3e28b650640fd3162152da1"); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class); + +throws(function() use ($pregenerated) { + $pregenerated->__toString(1); +}, MongoDB\Driver\Exception\InvalidArgumentException::class); ?> ===DONE=== @@ -83,4 +90,5 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException OK: Got MongoDB\Driver\Exception\InvalidArgumentException OK: Got MongoDB\Driver\Exception\InvalidArgumentException OK: Got MongoDB\Driver\Exception\InvalidArgumentException +OK: Got MongoDB\Driver\Exception\InvalidArgumentException ===DONE=== diff --git a/tests/bson/bson-objectid-tostring_error-001.phpt b/tests/bson/bson-objectid-tostring_error-001.phpt index 174b03c65..66c53fbf4 100644 --- a/tests/bson/bson-objectid-tostring_error-001.phpt +++ b/tests/bson/bson-objectid-tostring_error-001.phpt @@ -10,13 +10,14 @@ require_once __DIR__ . '/../utils/tools.php'; $pregenerated = new MongoDB\BSON\ObjectId("53e28b650640fd3162152de1"); -raises(function() use($pregenerated) { +echo throws(function() use($pregenerated) { $pregenerated->__toString(1); -}, E_WARNING); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== --EXPECTF-- -OK: Got E_WARNING +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\ObjectId::__toString() expects exactly 0 parameters, 1 given ===DONE=== diff --git a/tests/bson/bson-objectid_error-001.phpt b/tests/bson/bson-objectid_error-001.phpt index 131575ada..ee979486b 100644 --- a/tests/bson/bson-objectid_error-001.phpt +++ b/tests/bson/bson-objectid_error-001.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\BSON\ObjectId #001 error +MongoDB\BSON\ObjectId constructor type validation --SKIPIF-- =', '7.99'); ?> @@ -8,14 +8,14 @@ MongoDB\BSON\ObjectId #001 error require_once __DIR__ . '/../utils/tools.php'; -throws(function() { +echo throws(function() { new MongoDB\BSON\ObjectId(new stdclass); -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException +%SMongoDB\BSON\ObjectId::__construct()%sstring, %r(object|stdClass)%r given ===DONE=== - diff --git a/tests/bson/bson-regex_error-001.phpt b/tests/bson/bson-regex_error-001.phpt index 8a8d2ac7d..95ea57094 100644 --- a/tests/bson/bson-regex_error-001.phpt +++ b/tests/bson/bson-regex_error-001.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\BSON\Regex #001 error +MongoDB\BSON\Regex argument count errors --SKIPIF-- =', '7.99'); ?> @@ -8,20 +8,28 @@ MongoDB\BSON\Regex #001 error require_once __DIR__ . '/../utils/tools.php'; -$regexp = new MongoDB\BSON\Regex("regexp", "i"); -$regexp->getPattern(true); -$regexp->getFlags(true); +$regex = new MongoDB\BSON\Regex("regex", "i"); -throws(function() { +echo throws(function() use ($regex) { + $regex->getPattern(true); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +echo throws(function() use ($regex) { + $regex->getFlags(true); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; + +echo throws(function() { new MongoDB\BSON\Regex; -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== --EXPECTF-- -Warning: %s\Regex::getPattern() expects exactly 0 parameters, 1 given in %s on line %d - -Warning: %s\Regex::getFlags() expects exactly 0 parameters, 1 given in %s on line %d OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Regex::getPattern() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Regex::getFlags() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Regex::__construct() expects at least 1 %r(argument|parameter)%r, 0 given ===DONE=== diff --git a/tests/bson/bson-timestamp_error-001.phpt b/tests/bson/bson-timestamp_error-001.phpt index 5e758882f..c6a8eb09a 100644 --- a/tests/bson/bson-timestamp_error-001.phpt +++ b/tests/bson/bson-timestamp_error-001.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\BSON\Timestamp #001 error +MongoDB\BSON\Timestamp argument count errors --SKIPIF-- =', '7.99'); ?> @@ -8,14 +8,15 @@ MongoDB\BSON\Timestamp #001 error require_once __DIR__ . '/../utils/tools.php'; -throws(function() { +echo throws(function() { new MongoDB\BSON\Timestamp; -}, "MongoDB\\Driver\\Exception\\InvalidArgumentException"); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n" ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\BSON\Timestamp::__construct() expects exactly 2 %r(argument|parameter)%rs, 0 given ===DONE=== diff --git a/tests/manager/manager-ctor_error-001.phpt b/tests/manager/manager-ctor_error-001.phpt index 3e20ccb4d..f6f87e228 100644 --- a/tests/manager/manager-ctor_error-001.phpt +++ b/tests/manager/manager-ctor_error-001.phpt @@ -10,12 +10,12 @@ require_once __DIR__ . '/../utils/tools.php'; echo throws(function() { $manager = new MongoDB\Driver\Manager(null, [], [], 1); -}, "MongoDB\Driver\Exception\InvalidArgumentException"), "\n"; +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\Manager::__construct() expects at most 3 parameters, 4 given +MongoDB\Driver\Manager::__construct() expects at most 3 %r(argument|parameter)%rs, 4 given ===DONE=== diff --git a/tests/manager/manager-wakeup.phpt b/tests/manager/manager-wakeup.phpt index 9277ccbdc..cf07dcc8c 100644 --- a/tests/manager/manager-wakeup.phpt +++ b/tests/manager/manager-wakeup.phpt @@ -9,17 +9,21 @@ MongoDB\Driver\Manager: Manager cannot be woken up require_once __DIR__ . '/../utils/tools.php'; $manager = new MongoDB\Driver\Manager(); -throws(function() use($manager) { + +echo throws(function() use ($manager) { $manager->__wakeup(); -}, "MongoDB\Driver\Exception\RuntimeException"); +}, MongoDB\Driver\Exception\RuntimeException::class), "\n"; -$manager->__wakeup(1, 2); +echo throws(function() use ($manager) { + $manager->__wakeup(1, 2); +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== --EXPECTF-- OK: Got MongoDB\Driver\Exception\RuntimeException - -Warning: MongoDB\Driver\Manager::__wakeup() expects exactly 0 parameters, 2 given in %s on line %d +MongoDB\Driver objects cannot be serialized +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Manager::__wakeup() expects exactly 0 %r(argument|parameter)%rs, 2 given ===DONE=== diff --git a/tests/readConcern/readconcern-ctor_error-001.phpt b/tests/readConcern/readconcern-ctor_error-001.phpt index c2b0a58d6..4c160a4d7 100644 --- a/tests/readConcern/readconcern-ctor_error-001.phpt +++ b/tests/readConcern/readconcern-ctor_error-001.phpt @@ -9,12 +9,12 @@ require_once __DIR__ . "/../utils/basic.inc"; echo throws(function() { new MongoDB\Driver\ReadConcern("string", 1); -}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\ReadConcern::__construct() expects at most 1 parameter, 2 given +MongoDB\Driver\ReadConcern::__construct() expects at most 1 %r(argument|parameter)%r, 2 given ===DONE=== diff --git a/tests/readConcern/readconcern-ctor_error-002.phpt b/tests/readConcern/readconcern-ctor_error-002.phpt index 9151acb02..48446ac70 100644 --- a/tests/readConcern/readconcern-ctor_error-002.phpt +++ b/tests/readConcern/readconcern-ctor_error-002.phpt @@ -23,7 +23,7 @@ foreach ($tests as $test) { --EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\ReadConcern::__construct() expects parameter 1 to be string, array given +%SMongoDB\Driver\ReadConcern::__construct()%sstring, array given OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\ReadConcern::__construct() expects parameter 1 to be string, object given +%SMongoDB\Driver\ReadConcern::__construct()%sstring, %r(object|stdClass)%r given ===DONE=== diff --git a/tests/server/server-errors.phpt b/tests/server/server-errors.phpt index fb243ad2d..19f6f2611 100644 --- a/tests/server/server-errors.phpt +++ b/tests/server/server-errors.phpt @@ -1,5 +1,5 @@ --TEST-- -MongoDB\Driver\Server::executeQuery() with sort and empty filter +MongoDB\Driver\Server argument count errors --SKIPIF-- =', '7.99'); ?> @@ -12,52 +12,50 @@ require_once __DIR__ . "/../utils/basic.inc"; $manager = new MongoDB\Driver\Manager(URI); $server = $manager->executeQuery(NS, new MongoDB\Driver\Query(array()))->getServer(); -var_dump($server->getHost(true)); -var_dump($server->getTags(true)); -var_dump($server->getInfo(true)); -var_dump($server->getLatency(true)); -var_dump($server->getPort(true)); -var_dump($server->getType(true)); -var_dump($server->isPrimary(true)); -var_dump($server->isSecondary(true)); -var_dump($server->isArbiter(true)); -var_dump($server->isHidden(true)); -var_dump($server->isPassive(true)); +$methods = [ + 'getHost', + 'getTags', + 'getInfo', + 'getLatency', + 'getPort', + 'getType', + 'isPrimary', + 'isSecondary', + 'isArbiter', + 'isHidden', + 'isPassive', +]; + +foreach ($methods as $method) { + echo throws(function() use ($server, $method) { + $server->{$method}(true); + }, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; +} ?> ===DONE=== --EXPECTF-- -Warning: MongoDB\Driver\Server::getHost() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::getTags() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::getInfo() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::getLatency() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::getPort() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::getType() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::isPrimary() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::isSecondary() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::isArbiter() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::isHidden() expects exactly 0 parameters, 1 given in %s on line %d -NULL - -Warning: MongoDB\Driver\Server::isPassive() expects exactly 0 parameters, 1 given in %s on line %d -NULL +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getHost() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getTags() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getInfo() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getLatency() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getPort() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::getType() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::isPrimary() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::isSecondary() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::isArbiter() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::isHidden() expects exactly 0 %r(argument|parameter)%rs, 1 given +OK: Got MongoDB\Driver\Exception\InvalidArgumentException +MongoDB\Driver\Server::isPassive() expects exactly 0 %r(argument|parameter)%rs, 1 given ===DONE=== diff --git a/tests/session/session-startTransaction_error-002.phpt b/tests/session/session-startTransaction_error-002.phpt index c319577d0..37c7e1249 100644 --- a/tests/session/session-startTransaction_error-002.phpt +++ b/tests/session/session-startTransaction_error-002.phpt @@ -45,7 +45,7 @@ foreach ($options as $txnOptions) { echo raises(function() use ($session) { $session->startTransaction([ 'maxCommitTimeMS' => new stdClass ]); -}, E_NOTICE), "\n"; +}, E_NOTICE | E_WARNING), "\n"; ?> ===DONE=== @@ -77,6 +77,6 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "writeConcern" option to be MongoDB\Driver\WriteConcern, MongoDB\Driver\ReadPreference given OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "writeConcern" option to be MongoDB\Driver\WriteConcern, MongoDB\Driver\ReadPreference given -OK: Got E_NOTICE +OK: Got %r(E_NOTICE|E_WARNING)%r Object of class stdClass could not be converted to int ===DONE=== diff --git a/tests/session/session-startTransaction_error-004.phpt b/tests/session/session-startTransaction_error-004.phpt index dafda7351..4cb6a3ca4 100644 --- a/tests/session/session-startTransaction_error-004.phpt +++ b/tests/session/session-startTransaction_error-004.phpt @@ -1,14 +1,17 @@ --TEST-- -MongoDB\Driver\Session::startTransaction() with wrong argument for options array on PHP 7.0 +MongoDB\Driver\Session::startTransaction() with wrong argument for options array (PHP 7) --SKIPIF-- -=', '7.1.0'); ?> +', '7.99'); ?> --FILE-- startSession(); @@ -28,7 +31,7 @@ foreach ($options as $txnOptions) { --EXPECTF-- OK: Got TypeError -Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array, int%S given +Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array%r( or null)?%r, int%S given OK: Got TypeError -Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array, object given +Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array%r( or null)?%r, object given ===DONE=== diff --git a/tests/session/session-startTransaction_error-005.phpt b/tests/session/session-startTransaction_error-005.phpt index 324f5b42b..6a86fc8da 100644 --- a/tests/session/session-startTransaction_error-005.phpt +++ b/tests/session/session-startTransaction_error-005.phpt @@ -1,14 +1,16 @@ --TEST-- -MongoDB\Driver\Session::startTransaction() with wrong argument for options array on PHP 7 +MongoDB\Driver\Session::startTransaction() with wrong argument for options array (PHP 8) --SKIPIF-- - + --FILE-- startSession(); @@ -28,7 +30,7 @@ foreach ($options as $txnOptions) { --EXPECTF-- OK: Got TypeError -Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array or null, int%S given +%SMongoDB\Driver\Session::startTransaction()%sarray, int given OK: Got TypeError -Argument 1 passed to MongoDB\Driver\Session::startTransaction() must be of the type array or null, object given +%SMongoDB\Driver\Session::startTransaction()%sarray, %r(object|stdClass)%r given ===DONE=== diff --git a/tests/session/session_error-001.phpt b/tests/session/session_error-001.phpt index 29405bf2f..067ea4809 100644 --- a/tests/session/session_error-001.phpt +++ b/tests/session/session_error-001.phpt @@ -43,6 +43,12 @@ foreach ($options as $txnOptions) { }, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; } +echo raises(function() use ($manager) { + $manager->startSession([ + 'defaultTransactionOptions' => [ 'maxCommitTimeMS' => new stdClass ] + ]); +}, E_NOTICE | E_WARNING), "\n"; + ?> ===DONE=== @@ -77,4 +83,6 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "defaultTransactionOptions" option to be an array, int%S given OK: Got MongoDB\Driver\Exception\InvalidArgumentException Expected "defaultTransactionOptions" option to be an array, stdClass given +OK: Got %r(E_NOTICE|E_WARNING)%r +Object of class stdClass could not be converted to int ===DONE=== diff --git a/tests/utils/tools.php b/tests/utils/tools.php index 1fa2aeae6..ab7b99ffb 100644 --- a/tests/utils/tools.php +++ b/tests/utils/tools.php @@ -595,7 +595,7 @@ function raises($function, $type, $infunction = null) { restore_error_handler(); return $e->getMessage(); } - printf("OK: Got %s\n", severityToString($type)); + printf("OK: Got %s\n", severityToString($e->getSeverity())); } else { printf("ALMOST: Got %s - expected %s\n", get_class($e), $exceptionname); } diff --git a/tests/writeConcern/writeconcern-ctor_error-001.phpt b/tests/writeConcern/writeconcern-ctor_error-001.phpt index b71e530ad..b03dfdaa3 100644 --- a/tests/writeConcern/writeconcern-ctor_error-001.phpt +++ b/tests/writeConcern/writeconcern-ctor_error-001.phpt @@ -10,12 +10,12 @@ require_once __DIR__ . '/../utils/tools.php'; echo throws(function() { new MongoDB\Driver\WriteConcern("string", 10000, false, 1); -}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n"; +}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n"; ?> ===DONE=== ---EXPECT-- +--EXPECTF-- OK: Got MongoDB\Driver\Exception\InvalidArgumentException -MongoDB\Driver\WriteConcern::__construct() expects at most 3 parameters, 4 given +MongoDB\Driver\WriteConcern::__construct() expects at most 3 %r(argument|parameter)%rs, 4 given ===DONE===