@@ -46,7 +46,7 @@ PHONGO_API zend_class_entry *php_phongo_regex_ce;
4646
4747zend_object_handlers php_phongo_handler_regex ;
4848
49- /* Initialize the object from a string and return whether it was successful. */
49+ /* Initialize the object and return whether it was successful. */
5050static bool php_phongo_regex_init (php_phongo_regex_t * intern , const char * pattern , phongo_zpp_char_len pattern_len , const char * flags , phongo_zpp_char_len flags_len )
5151{
5252 intern -> pattern = estrndup (pattern , pattern_len );
@@ -57,8 +57,9 @@ static bool php_phongo_regex_init(php_phongo_regex_t *intern, const char *patter
5757 return true;
5858}
5959
60- /* Initialize the object from a HashTable and return whether it was successful. */
61- static bool php_phongo_regex_init_from_hash (php_phongo_regex_t * intern , HashTable * props )
60+ /* Initialize the object from a HashTable and return whether it was successful.
61+ * An exception will be thrown on error. */
62+ static bool php_phongo_regex_init_from_hash (php_phongo_regex_t * intern , HashTable * props TSRMLS_DC )
6263{
6364#if PHP_VERSION_ID >= 70000
6465 zval * pattern , * flags ;
@@ -75,6 +76,8 @@ static bool php_phongo_regex_init_from_hash(php_phongo_regex_t *intern, HashTabl
7576 return php_phongo_regex_init (intern , Z_STRVAL_PP (pattern ), Z_STRLEN_PP (pattern ), Z_STRVAL_PP (flags ), Z_STRLEN_PP (flags ));
7677 }
7778#endif
79+
80+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires \"pattern\" and \"flags\" string fields" , ZSTR_VAL (php_phongo_regex_ce -> name ));
7881 return false;
7982}
8083
@@ -154,9 +157,7 @@ PHP_METHOD(Regex, __set_state)
154157 intern = Z_REGEX_OBJ_P (return_value );
155158 props = Z_ARRVAL_P (array );
156159
157- if (!php_phongo_regex_init_from_hash (intern , props )) {
158- php_error (E_ERROR , "Invalid serialization data for Regex object" );
159- }
160+ php_phongo_regex_init_from_hash (intern , props TSRMLS_CC );
160161}
161162/* }}} */
162163
@@ -196,9 +197,7 @@ PHP_METHOD(Regex, __wakeup)
196197 intern = Z_REGEX_OBJ_P (getThis ());
197198 props = zend_std_get_properties (getThis () TSRMLS_CC );
198199
199- if (!php_phongo_regex_init_from_hash (intern , props )) {
200- php_error (E_ERROR , "Invalid serialization data for Regex object" );
201- }
200+ php_phongo_regex_init_from_hash (intern , props TSRMLS_CC );
202201}
203202/* }}} */
204203
0 commit comments