@@ -1256,6 +1256,35 @@ static void reflection_class_constant_factory(zend_class_entry *ce, zend_string
1256
1256
}
1257
1257
/* }}} */
1258
1258
1259
+ static void reflection_export_impl (zval * return_value , zval * object , zend_bool return_output ) {
1260
+ zval fname , retval ;
1261
+ int result ;
1262
+
1263
+ /* Invoke the __toString() method */
1264
+ ZVAL_STRINGL (& fname , "__tostring" , sizeof ("__tostring" ) - 1 );
1265
+ result = call_user_function (NULL , object , & fname , & retval , 0 , NULL );
1266
+ zval_ptr_dtor_str (& fname );
1267
+
1268
+ if (result == FAILURE ) {
1269
+ _DO_THROW ("Invocation of method __toString() failed" );
1270
+ return ;
1271
+ }
1272
+
1273
+ if (Z_TYPE (retval ) == IS_UNDEF ) {
1274
+ php_error_docref (NULL , E_WARNING , "%s::__toString() did not return anything" , ZSTR_VAL (Z_OBJCE_P (object )-> name ));
1275
+ RETURN_FALSE ;
1276
+ }
1277
+
1278
+ if (return_output ) {
1279
+ ZVAL_COPY_VALUE (return_value , & retval );
1280
+ } else {
1281
+ /* No need for _r variant, return of __toString should always be a string */
1282
+ zend_print_zval (& retval , 0 );
1283
+ zend_printf ("\n" );
1284
+ zval_ptr_dtor (& retval );
1285
+ }
1286
+ }
1287
+
1259
1288
/* {{{ _reflection_export */
1260
1289
static void _reflection_export (INTERNAL_FUNCTION_PARAMETERS , zend_class_entry * ce_ptr , int ctor_argc )
1261
1290
{
@@ -1315,33 +1344,7 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c
1315
1344
return ;
1316
1345
}
1317
1346
1318
- /* Call static reflection::export */
1319
- ZVAL_COPY_VALUE (& params [0 ], & reflector );
1320
- ZVAL_BOOL (& params [1 ], return_output );
1321
-
1322
- ZVAL_STRINGL (& fci .function_name , "reflection::export" , sizeof ("reflection::export" ) - 1 );
1323
- fci .object = NULL ;
1324
- fci .retval = & retval ;
1325
- fci .param_count = 2 ;
1326
- fci .params = params ;
1327
- fci .no_separation = 1 ;
1328
-
1329
- result = zend_call_function (& fci , NULL );
1330
-
1331
- zval_ptr_dtor (& fci .function_name );
1332
-
1333
- if (result == FAILURE && EG (exception ) == NULL ) {
1334
- zval_ptr_dtor (& reflector );
1335
- zval_ptr_dtor (& retval );
1336
- _DO_THROW ("Could not execute reflection::export()" );
1337
- return ;
1338
- }
1339
-
1340
- if (return_output ) {
1341
- ZVAL_COPY_VALUE (return_value , & retval );
1342
- } else {
1343
- zval_ptr_dtor (& retval );
1344
- }
1347
+ reflection_export_impl (return_value , & reflector , return_output );
1345
1348
1346
1349
/* Destruct reflector which is no longer needed */
1347
1350
zval_ptr_dtor (& reflector );
@@ -1404,8 +1407,7 @@ ZEND_METHOD(reflection, __clone)
1404
1407
Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
1405
1408
ZEND_METHOD (reflection , export )
1406
1409
{
1407
- zval * object , fname , retval ;
1408
- int result ;
1410
+ zval * object ;
1409
1411
zend_bool return_output = 0 ;
1410
1412
1411
1413
ZEND_PARSE_PARAMETERS_START (1 , 2 )
@@ -1414,29 +1416,7 @@ ZEND_METHOD(reflection, export)
1414
1416
Z_PARAM_BOOL (return_output )
1415
1417
ZEND_PARSE_PARAMETERS_END ();
1416
1418
1417
- /* Invoke the __toString() method */
1418
- ZVAL_STRINGL (& fname , "__tostring" , sizeof ("__tostring" ) - 1 );
1419
- result = call_user_function (NULL , object , & fname , & retval , 0 , NULL );
1420
- zval_ptr_dtor_str (& fname );
1421
-
1422
- if (result == FAILURE ) {
1423
- _DO_THROW ("Invocation of method __toString() failed" );
1424
- return ;
1425
- }
1426
-
1427
- if (Z_TYPE (retval ) == IS_UNDEF ) {
1428
- php_error_docref (NULL , E_WARNING , "%s::__toString() did not return anything" , ZSTR_VAL (Z_OBJCE_P (object )-> name ));
1429
- RETURN_FALSE ;
1430
- }
1431
-
1432
- if (return_output ) {
1433
- ZVAL_COPY_VALUE (return_value , & retval );
1434
- } else {
1435
- /* No need for _r variant, return of __toString should always be a string */
1436
- zend_print_zval (& retval , 0 );
1437
- zend_printf ("\n" );
1438
- zval_ptr_dtor (& retval );
1439
- }
1419
+ reflection_export_impl (return_value , object , return_output );
1440
1420
}
1441
1421
/* }}} */
1442
1422
0 commit comments