@@ -1457,6 +1457,54 @@ static void _reflection_export(INTERNAL_FUNCTION_PARAMETERS, zend_class_entry *c
1457
1457
}
1458
1458
/* }}} */
1459
1459
1460
+ /* {{{ _reflection_param_get_default_param */
1461
+ static parameter_reference * _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAMETERS )
1462
+ {
1463
+ reflection_object * intern ;
1464
+ parameter_reference * param ;
1465
+
1466
+ intern = (reflection_object * ) zend_object_store_get_object (getThis () TSRMLS_CC );
1467
+ if (intern == NULL || intern -> ptr == NULL ) {
1468
+ if (EG (exception ) && Z_OBJCE_P (EG (exception )) == reflection_exception_ptr ) {
1469
+ return NULL ;
1470
+ }
1471
+ php_error_docref (NULL TSRMLS_CC , E_ERROR , "Internal error: Failed to retrieve the reflection object" );
1472
+ }
1473
+
1474
+ param = intern -> ptr ;
1475
+ if (param -> fptr -> type != ZEND_USER_FUNCTION ) {
1476
+ zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Cannot determine default value for internal functions" );
1477
+ return NULL ;
1478
+ }
1479
+
1480
+ if (param -> offset < param -> required ) {
1481
+ zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Parameter is not optional" );
1482
+ return NULL ;
1483
+ }
1484
+
1485
+ return param ;
1486
+ }
1487
+ /* }}} */
1488
+
1489
+ /* {{{ _reflection_param_get_default_precv */
1490
+ static zend_op * _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAMETERS , parameter_reference * param )
1491
+ {
1492
+ zend_op * precv ;
1493
+
1494
+ if (param == NULL ) {
1495
+ return NULL ;
1496
+ }
1497
+
1498
+ precv = _get_recv_op ((zend_op_array * )param -> fptr , param -> offset );
1499
+ if (!precv || precv -> opcode != ZEND_RECV_INIT || precv -> op2_type == IS_UNUSED ) {
1500
+ zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Internal error" );
1501
+ return NULL ;
1502
+ }
1503
+
1504
+ return precv ;
1505
+ }
1506
+ /* }}} */
1507
+
1460
1508
/* {{{ Preventing __clone from being called */
1461
1509
ZEND_METHOD (reflection , __clone )
1462
1510
{
@@ -2535,27 +2583,20 @@ ZEND_METHOD(reflection_parameter, isDefaultValueAvailable)
2535
2583
Returns the default value of this parameter or throws an exception */
2536
2584
ZEND_METHOD (reflection_parameter , getDefaultValue )
2537
2585
{
2538
- reflection_object * intern ;
2539
2586
parameter_reference * param ;
2540
2587
zend_op * precv ;
2541
2588
2542
2589
if (zend_parse_parameters_none () == FAILURE ) {
2543
2590
return ;
2544
2591
}
2545
- GET_REFLECTION_OBJECT_PTR (param );
2546
2592
2547
- if (param -> fptr -> type != ZEND_USER_FUNCTION )
2548
- {
2549
- zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Cannot determine default value for internal functions" );
2593
+ param = _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAM_PASSTHRU );
2594
+ if (!param ) {
2550
2595
return ;
2551
2596
}
2552
- if (param -> offset < param -> required ) {
2553
- zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Parameter is not optional" );
2554
- return ;
2555
- }
2556
- precv = _get_recv_op ((zend_op_array * )param -> fptr , param -> offset );
2557
- if (!precv || precv -> opcode != ZEND_RECV_INIT || precv -> op2_type == IS_UNUSED ) {
2558
- zend_throw_exception_ex (reflection_exception_ptr , 0 TSRMLS_CC , "Internal error" );
2597
+
2598
+ precv = _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAM_PASSTHRU , param );
2599
+ if (!precv ) {
2559
2600
return ;
2560
2601
}
2561
2602
@@ -2568,6 +2609,54 @@ ZEND_METHOD(reflection_parameter, getDefaultValue)
2568
2609
}
2569
2610
/* }}} */
2570
2611
2612
+ /* {{{ proto public bool ReflectionParameter::isDefaultValueConstant()
2613
+ Returns whether the default value of this parameter is constant */
2614
+ ZEND_METHOD (reflection_parameter , isDefaultValueConstant )
2615
+ {
2616
+ zend_op * precv ;
2617
+ parameter_reference * param ;
2618
+
2619
+ if (zend_parse_parameters_none () == FAILURE ) {
2620
+ return ;
2621
+ }
2622
+
2623
+ param = _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAM_PASSTHRU );
2624
+ if (!param ) {
2625
+ RETURN_FALSE ;
2626
+ }
2627
+
2628
+ precv = _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAM_PASSTHRU , param );
2629
+ if (precv && (Z_TYPE_P (precv -> op2 .zv ) & IS_CONSTANT_TYPE_MASK ) == IS_CONSTANT ) {
2630
+ RETURN_TRUE ;
2631
+ }
2632
+
2633
+ RETURN_FALSE ;
2634
+ }
2635
+ /* }}} */
2636
+
2637
+ /* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName()
2638
+ Returns the default value's constant name if default value is constant or null */
2639
+ ZEND_METHOD (reflection_parameter , getDefaultValueConstantName )
2640
+ {
2641
+ zend_op * precv ;
2642
+ parameter_reference * param ;
2643
+
2644
+ if (zend_parse_parameters_none () == FAILURE ) {
2645
+ return ;
2646
+ }
2647
+
2648
+ param = _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAM_PASSTHRU );
2649
+ if (!param ) {
2650
+ return ;
2651
+ }
2652
+
2653
+ precv = _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAM_PASSTHRU , param );
2654
+ if (precv && (Z_TYPE_P (precv -> op2 .zv ) & IS_CONSTANT_TYPE_MASK ) == IS_CONSTANT ) {
2655
+ RETURN_STRINGL (Z_STRVAL_P (precv -> op2 .zv ), Z_STRLEN_P (precv -> op2 .zv ), 1 );
2656
+ }
2657
+ }
2658
+ /* }}} */
2659
+
2571
2660
/* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException
2572
2661
Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
2573
2662
ZEND_METHOD (reflection_method , export )
@@ -5903,6 +5992,8 @@ static const zend_function_entry reflection_parameter_functions[] = {
5903
5992
ZEND_ME (reflection_parameter , isOptional , arginfo_reflection__void , 0 )
5904
5993
ZEND_ME (reflection_parameter , isDefaultValueAvailable , arginfo_reflection__void , 0 )
5905
5994
ZEND_ME (reflection_parameter , getDefaultValue , arginfo_reflection__void , 0 )
5995
+ ZEND_ME (reflection_parameter , isDefaultValueConstant , arginfo_reflection__void , 0 )
5996
+ ZEND_ME (reflection_parameter , getDefaultValueConstantName , arginfo_reflection__void , 0 )
5906
5997
PHP_FE_END
5907
5998
};
5908
5999
0 commit comments