@@ -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
@@ -2569,6 +2610,54 @@ ZEND_METHOD(reflection_parameter, getDefaultValue)
2569
2610
}
2570
2611
/* }}} */
2571
2612
2613
+ /* {{{ proto public bool ReflectionParameter::isDefaultValueConstant()
2614
+ Returns whether the default value of this parameter is constant */
2615
+ ZEND_METHOD (reflection_parameter , isDefaultValueConstant )
2616
+ {
2617
+ zend_op * precv ;
2618
+ parameter_reference * param ;
2619
+
2620
+ if (zend_parse_parameters_none () == FAILURE ) {
2621
+ return ;
2622
+ }
2623
+
2624
+ param = _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAM_PASSTHRU );
2625
+ if (!param ) {
2626
+ RETURN_FALSE ;
2627
+ }
2628
+
2629
+ precv = _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAM_PASSTHRU , param );
2630
+ if (precv && (Z_TYPE_P (precv -> op2 .zv ) & IS_CONSTANT_TYPE_MASK ) == IS_CONSTANT ) {
2631
+ RETURN_TRUE ;
2632
+ }
2633
+
2634
+ RETURN_FALSE ;
2635
+ }
2636
+ /* }}} */
2637
+
2638
+ /* {{{ proto public mixed ReflectionParameter::getDefaultValueConstantName()
2639
+ Returns the default value's constant name if default value is constant or null */
2640
+ ZEND_METHOD (reflection_parameter , getDefaultValueConstantName )
2641
+ {
2642
+ zend_op * precv ;
2643
+ parameter_reference * param ;
2644
+
2645
+ if (zend_parse_parameters_none () == FAILURE ) {
2646
+ return ;
2647
+ }
2648
+
2649
+ param = _reflection_param_get_default_param (INTERNAL_FUNCTION_PARAM_PASSTHRU );
2650
+ if (!param ) {
2651
+ return ;
2652
+ }
2653
+
2654
+ precv = _reflection_param_get_default_precv (INTERNAL_FUNCTION_PARAM_PASSTHRU , param );
2655
+ if (precv && (Z_TYPE_P (precv -> op2 .zv ) & IS_CONSTANT_TYPE_MASK ) == IS_CONSTANT ) {
2656
+ RETURN_STRINGL (Z_STRVAL_P (precv -> op2 .zv ), Z_STRLEN_P (precv -> op2 .zv ), 1 );
2657
+ }
2658
+ }
2659
+ /* }}} */
2660
+
2572
2661
/* {{{ proto public static mixed ReflectionMethod::export(mixed class, string name [, bool return]) throws ReflectionException
2573
2662
Exports a reflection object. Returns the output if TRUE is specified for return, printing it otherwise. */
2574
2663
ZEND_METHOD (reflection_method , export )
@@ -5912,6 +6001,8 @@ static const zend_function_entry reflection_parameter_functions[] = {
5912
6001
ZEND_ME (reflection_parameter , isOptional , arginfo_reflection__void , 0 )
5913
6002
ZEND_ME (reflection_parameter , isDefaultValueAvailable , arginfo_reflection__void , 0 )
5914
6003
ZEND_ME (reflection_parameter , getDefaultValue , arginfo_reflection__void , 0 )
6004
+ ZEND_ME (reflection_parameter , isDefaultValueConstant , arginfo_reflection__void , 0 )
6005
+ ZEND_ME (reflection_parameter , getDefaultValueConstantName , arginfo_reflection__void , 0 )
5915
6006
PHP_FE_END
5916
6007
};
5917
6008
0 commit comments