@@ -139,22 +139,29 @@ PHP_MINFO_FUNCTION(assert) /* {{{ */
139
139
PHP_FUNCTION (assert )
140
140
{
141
141
zval * assertion ;
142
- zval * description = NULL ;
142
+ zend_string * description_str = NULL ;
143
+ zend_object * description_obj = NULL ;
143
144
144
- if (! ASSERTG (active )) {
145
+ if (!ASSERTG (active )) {
145
146
RETURN_TRUE ;
146
147
}
147
148
148
149
ZEND_PARSE_PARAMETERS_START (1 , 2 )
149
150
Z_PARAM_ZVAL (assertion )
150
151
Z_PARAM_OPTIONAL
151
- Z_PARAM_ZVAL ( description )
152
+ Z_PARAM_STR_OR_OBJ_OF_CLASS_OR_NULL ( description_str , description_obj , zend_ce_throwable )
152
153
ZEND_PARSE_PARAMETERS_END ();
153
154
154
155
if (zend_is_true (assertion )) {
155
156
RETURN_TRUE ;
156
157
}
157
158
159
+ if (description_obj ) {
160
+ GC_ADDREF (description_obj );
161
+ zend_throw_exception_internal (description_obj );
162
+ RETURN_THROWS ();
163
+ }
164
+
158
165
if (Z_TYPE (ASSERTG (callback )) == IS_UNDEF && ASSERTG (cb )) {
159
166
ZVAL_STRING (& ASSERTG (callback ), ASSERTG (cb ));
160
167
}
@@ -171,15 +178,14 @@ PHP_FUNCTION(assert)
171
178
172
179
ZVAL_FALSE (& retval );
173
180
174
- /* XXX do we want to check for error here? */
175
- if (!description ) {
176
- call_user_function (NULL , NULL , & ASSERTG (callback ), & retval , 3 , args );
181
+ if (description_str ) {
182
+ ZVAL_STR (& args [3 ], description_str );
183
+ call_user_function (NULL , NULL , & ASSERTG (callback ), & retval , 4 , args );
184
+ zval_ptr_dtor (& (args [3 ]));
177
185
zval_ptr_dtor (& (args [2 ]));
178
186
zval_ptr_dtor (& (args [0 ]));
179
187
} else {
180
- ZVAL_STR (& args [3 ], zval_get_string (description ));
181
- call_user_function (NULL , NULL , & ASSERTG (callback ), & retval , 4 , args );
182
- zval_ptr_dtor (& (args [3 ]));
188
+ call_user_function (NULL , NULL , & ASSERTG (callback ), & retval , 3 , args );
183
189
zval_ptr_dtor (& (args [2 ]));
184
190
zval_ptr_dtor (& (args [0 ]));
185
191
}
@@ -188,25 +194,9 @@ PHP_FUNCTION(assert)
188
194
}
189
195
190
196
if (ASSERTG (exception )) {
191
- if (!description ) {
192
- zend_throw_exception (assertion_error_ce , NULL , E_ERROR );
193
- } else if (Z_TYPE_P (description ) == IS_OBJECT &&
194
- instanceof_function (Z_OBJCE_P (description ), zend_ce_throwable )) {
195
- Z_ADDREF_P (description );
196
- zend_throw_exception_object (description );
197
- } else {
198
- zend_string * str = zval_get_string (description );
199
- zend_throw_exception (assertion_error_ce , ZSTR_VAL (str ), E_ERROR );
200
- zend_string_release_ex (str , 0 );
201
- }
197
+ zend_throw_exception (assertion_error_ce , description_str ? ZSTR_VAL (description_str ) : NULL , E_ERROR );
202
198
} else if (ASSERTG (warning )) {
203
- if (!description ) {
204
- php_error_docref (NULL , E_WARNING , "Assertion failed" );
205
- } else {
206
- zend_string * str = zval_get_string (description );
207
- php_error_docref (NULL , E_WARNING , "%s failed" , ZSTR_VAL (str ));
208
- zend_string_release_ex (str , 0 );
209
- }
199
+ php_error_docref (NULL , E_WARNING , "%s failed" , description_str ? ZSTR_VAL (description_str ) : "Assertion failed" );
210
200
}
211
201
212
202
if (ASSERTG (bail )) {
@@ -289,9 +279,14 @@ PHP_FUNCTION(assert_options)
289
279
} else {
290
280
RETVAL_NULL ();
291
281
}
282
+
292
283
if (ac == 2 ) {
293
284
zval_ptr_dtor (& ASSERTG (callback ));
294
- ZVAL_COPY (& ASSERTG (callback ), value );
285
+ if (Z_TYPE_P (value ) == IS_NULL ) {
286
+ ZVAL_UNDEF (& ASSERTG (callback ));
287
+ } else {
288
+ ZVAL_COPY (& ASSERTG (callback ), value );
289
+ }
295
290
}
296
291
return ;
297
292
@@ -312,7 +307,7 @@ PHP_FUNCTION(assert_options)
312
307
break ;
313
308
314
309
default :
315
- zend_argument_value_error (1 , "must have a valid value " );
310
+ zend_argument_value_error (1 , "must be an ASSERT_* constant " );
316
311
RETURN_THROWS ();
317
312
}
318
313
}
0 commit comments