@@ -46,10 +46,12 @@ PHONGO_API zend_class_entry *php_phongo_binary_ce;
46
46
47
47
zend_object_handlers php_phongo_handler_binary ;
48
48
49
- /* Initialize the object from a string and return whether it was successful. */
50
- static bool php_phongo_binary_init (php_phongo_binary_t * intern , const char * data , phongo_zpp_char_len data_len , phongo_long type )
49
+ /* Initialize the object and return whether it was successful. An exception will
50
+ * be thrown on error. */
51
+ static bool php_phongo_binary_init (php_phongo_binary_t * intern , const char * data , phongo_zpp_char_len data_len , phongo_long type TSRMLS_DC )
51
52
{
52
53
if (type < 0 || type > UINT8_MAX ) {
54
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected type to be an unsigned 8-bit integer, %" PHONGO_LONG_FORMAT " given" , type );
53
55
return false;
54
56
}
55
57
@@ -60,24 +62,27 @@ static bool php_phongo_binary_init(php_phongo_binary_t *intern, const char *data
60
62
return true;
61
63
}
62
64
63
- /* Initialize the object from a HashTable and return whether it was successful. */
64
- static bool php_phongo_binary_init_from_hash (php_phongo_binary_t * intern , HashTable * props )
65
+ /* Initialize the object from a HashTable and return whether it was successful.
66
+ * An exception will be thrown on error. */
67
+ static bool php_phongo_binary_init_from_hash (php_phongo_binary_t * intern , HashTable * props TSRMLS_DC )
65
68
{
66
69
#if PHP_VERSION_ID >= 70000
67
70
zval * data , * type ;
68
71
69
72
if ((data = zend_hash_str_find (props , "data" , sizeof ("data" )- 1 )) && Z_TYPE_P (data ) == IS_STRING &&
70
73
(type = zend_hash_str_find (props , "type" , sizeof ("type" )- 1 )) && Z_TYPE_P (type ) == IS_LONG ) {
71
- return php_phongo_binary_init (intern , Z_STRVAL_P (data ), Z_STRLEN_P (data ), Z_LVAL_P (type ));
74
+ return php_phongo_binary_init (intern , Z_STRVAL_P (data ), Z_STRLEN_P (data ), Z_LVAL_P (type ) TSRMLS_CC );
72
75
}
73
76
#else
74
77
zval * * data , * * type ;
75
78
76
79
if (zend_hash_find (props , "data" , sizeof ("data" ), (void * * ) & data ) == SUCCESS && Z_TYPE_PP (data ) == IS_STRING &&
77
80
zend_hash_find (props , "type" , sizeof ("type" ), (void * * ) & type ) == SUCCESS && Z_TYPE_PP (type ) == IS_LONG ) {
78
- return php_phongo_binary_init (intern , Z_STRVAL_PP (data ), Z_STRLEN_PP (data ), Z_LVAL_PP (type ));
81
+ return php_phongo_binary_init (intern , Z_STRVAL_PP (data ), Z_STRLEN_PP (data ), Z_LVAL_PP (type ) TSRMLS_CC );
79
82
}
80
83
#endif
84
+
85
+ phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "%s initialization requires \"data\" string and \"type\" integer fields" , ZSTR_VAL (php_phongo_binary_ce -> name ));
81
86
return false;
82
87
}
83
88
@@ -101,9 +106,7 @@ PHP_METHOD(Binary, __construct)
101
106
}
102
107
zend_restore_error_handling (& error_handling TSRMLS_CC );
103
108
104
- if (!php_phongo_binary_init (intern , data , data_len , type )) {
105
- phongo_throw_exception (PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC , "Expected type to be an unsigned 8-bit integer, %" PHONGO_LONG_FORMAT " given" , type );
106
- }
109
+ php_phongo_binary_init (intern , data , data_len , type TSRMLS_CC );
107
110
}
108
111
/* }}} */
109
112
@@ -124,9 +127,7 @@ PHP_METHOD(Binary, __set_state)
124
127
intern = Z_BINARY_OBJ_P (return_value );
125
128
props = Z_ARRVAL_P (array );
126
129
127
- if (!php_phongo_binary_init_from_hash (intern , props )) {
128
- php_error (E_ERROR , "Invalid serialization data for Binary object" );
129
- }
130
+ php_phongo_binary_init_from_hash (intern , props TSRMLS_CC );
130
131
}
131
132
/* }}} */
132
133
@@ -144,9 +145,7 @@ PHP_METHOD(Binary, __wakeup)
144
145
intern = Z_BINARY_OBJ_P (getThis ());
145
146
props = zend_std_get_properties (getThis () TSRMLS_CC );
146
147
147
- if (!php_phongo_binary_init_from_hash (intern , props )) {
148
- php_error (E_ERROR , "Invalid serialization data for Binary object" );
149
- }
148
+ php_phongo_binary_init_from_hash (intern , props TSRMLS_CC );
150
149
}
151
150
/* }}} */
152
151
0 commit comments