@@ -584,6 +584,39 @@ static zend_op* _get_recv_op(zend_op_array *op_array, uint32_t offset)
584
584
}
585
585
/* }}} */
586
586
587
+ static int format_default_value (smart_str * str , zval * value , zend_class_entry * scope ) {
588
+ zval zv ;
589
+ ZVAL_COPY (& zv , value );
590
+ if (UNEXPECTED (zval_update_constant_ex (& zv , scope ) == FAILURE )) {
591
+ zval_ptr_dtor (& zv );
592
+ return FAILURE ;
593
+ }
594
+
595
+ if (Z_TYPE (zv ) == IS_TRUE ) {
596
+ smart_str_appends (str , "true" );
597
+ } else if (Z_TYPE (zv ) == IS_FALSE ) {
598
+ smart_str_appends (str , "false" );
599
+ } else if (Z_TYPE (zv ) == IS_NULL ) {
600
+ smart_str_appends (str , "NULL" );
601
+ } else if (Z_TYPE (zv ) == IS_STRING ) {
602
+ smart_str_appendc (str , '\'' );
603
+ smart_str_appendl (str , Z_STRVAL (zv ), MIN (Z_STRLEN (zv ), 15 ));
604
+ if (Z_STRLEN (zv ) > 15 ) {
605
+ smart_str_appends (str , "..." );
606
+ }
607
+ smart_str_appendc (str , '\'' );
608
+ } else if (Z_TYPE (zv ) == IS_ARRAY ) {
609
+ smart_str_appends (str , "Array" );
610
+ } else {
611
+ zend_string * tmp_zv_str ;
612
+ zend_string * zv_str = zval_get_tmp_string (& zv , & tmp_zv_str );
613
+ smart_str_append (str , zv_str );
614
+ zend_tmp_string_release (tmp_zv_str );
615
+ }
616
+ zval_ptr_dtor (& zv );
617
+ return SUCCESS ;
618
+ }
619
+
587
620
/* {{{ _parameter_string */
588
621
static void _parameter_string (smart_str * str , zend_function * fptr , struct _zend_arg_info * arg_info , uint32_t offset , zend_bool required , char * indent )
589
622
{
@@ -617,36 +650,10 @@ static void _parameter_string(smart_str *str, zend_function *fptr, struct _zend_
617
650
if (fptr -> type == ZEND_USER_FUNCTION && !required ) {
618
651
zend_op * precv = _get_recv_op ((zend_op_array * )fptr , offset );
619
652
if (precv && precv -> opcode == ZEND_RECV_INIT && precv -> op2_type != IS_UNUSED ) {
620
- zval zv ;
621
-
622
653
smart_str_appends (str , " = " );
623
- ZVAL_COPY (& zv , RT_CONSTANT (precv , precv -> op2 ));
624
- if (UNEXPECTED (zval_update_constant_ex (& zv , fptr -> common .scope ) == FAILURE )) {
625
- zval_ptr_dtor (& zv );
654
+ if (format_default_value (str , RT_CONSTANT (precv , precv -> op2 ), fptr -> common .scope ) == FAILURE ) {
626
655
return ;
627
656
}
628
- if (Z_TYPE (zv ) == IS_TRUE ) {
629
- smart_str_appends (str , "true" );
630
- } else if (Z_TYPE (zv ) == IS_FALSE ) {
631
- smart_str_appends (str , "false" );
632
- } else if (Z_TYPE (zv ) == IS_NULL ) {
633
- smart_str_appends (str , "NULL" );
634
- } else if (Z_TYPE (zv ) == IS_STRING ) {
635
- smart_str_appendc (str , '\'' );
636
- smart_str_appendl (str , Z_STRVAL (zv ), MIN (Z_STRLEN (zv ), 15 ));
637
- if (Z_STRLEN (zv ) > 15 ) {
638
- smart_str_appends (str , "..." );
639
- }
640
- smart_str_appendc (str , '\'' );
641
- } else if (Z_TYPE (zv ) == IS_ARRAY ) {
642
- smart_str_appends (str , "Array" );
643
- } else {
644
- zend_string * tmp_zv_str ;
645
- zend_string * zv_str = zval_get_tmp_string (& zv , & tmp_zv_str );
646
- smart_str_append (str , zv_str );
647
- zend_tmp_string_release (tmp_zv_str );
648
- }
649
- zval_ptr_dtor (& zv );
650
657
}
651
658
}
652
659
smart_str_appends (str , " ]" );
@@ -818,6 +825,17 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
818
825
}
819
826
/* }}} */
820
827
828
+ static zval * property_get_default (zend_property_info * prop_info ) {
829
+ zend_class_entry * ce = prop_info -> ce ;
830
+ if (prop_info -> flags & ZEND_ACC_STATIC ) {
831
+ zval * prop = & ce -> default_static_members_table [prop_info -> offset ];
832
+ ZVAL_DEINDIRECT (prop );
833
+ return prop ;
834
+ } else {
835
+ return & ce -> default_properties_table [OBJ_PROP_TO_NUM (prop_info -> offset )];
836
+ }
837
+ }
838
+
821
839
/* {{{ _property_string */
822
840
static void _property_string (smart_str * str , zend_property_info * prop , const char * prop_name , char * indent )
823
841
{
@@ -855,6 +873,14 @@ static void _property_string(smart_str *str, zend_property_info *prop, const cha
855
873
zend_unmangle_property_name (prop -> name , & class_name , & prop_name );
856
874
}
857
875
smart_str_append_printf (str , "$%s" , prop_name );
876
+
877
+ zval * default_value = property_get_default (prop );
878
+ if (!Z_ISUNDEF_P (default_value )) {
879
+ smart_str_appends (str , " = " );
880
+ if (format_default_value (str , default_value , prop -> ce ) == FAILURE ) {
881
+ return ;
882
+ }
883
+ }
858
884
}
859
885
860
886
smart_str_appends (str , " ]\n" );
@@ -3673,7 +3699,7 @@ ZEND_METHOD(reflection_class, __construct)
3673
3699
/* }}} */
3674
3700
3675
3701
/* {{{ add_class_vars */
3676
- static void add_class_vars (zend_class_entry * ce , int statics , zval * return_value )
3702
+ static void add_class_vars (zend_class_entry * ce , zend_bool statics , zval * return_value )
3677
3703
{
3678
3704
zend_property_info * prop_info ;
3679
3705
zval * prop , prop_copy ;
@@ -3686,14 +3712,14 @@ static void add_class_vars(zend_class_entry *ce, int statics, zval *return_value
3686
3712
prop_info -> ce != ce )) {
3687
3713
continue ;
3688
3714
}
3689
- prop = NULL ;
3690
- if (statics && (prop_info -> flags & ZEND_ACC_STATIC ) != 0 ) {
3691
- prop = & ce -> default_static_members_table [prop_info -> offset ];
3692
- ZVAL_DEINDIRECT (prop );
3693
- } else if (!statics && (prop_info -> flags & ZEND_ACC_STATIC ) == 0 ) {
3694
- prop = & ce -> default_properties_table [OBJ_PROP_TO_NUM (prop_info -> offset )];
3715
+
3716
+ zend_bool is_static = (prop_info -> flags & ZEND_ACC_STATIC ) != 0 ;
3717
+ if (statics != is_static ) {
3718
+ continue ;
3695
3719
}
3696
- if (!prop || (ZEND_TYPE_IS_SET (prop_info -> type ) && Z_ISUNDEF_P (prop ))) {
3720
+
3721
+ prop = property_get_default (prop_info );
3722
+ if (Z_ISUNDEF_P (prop )) {
3697
3723
continue ;
3698
3724
}
3699
3725
@@ -5544,7 +5570,6 @@ ZEND_METHOD(reflection_property, hasDefaultValue)
5544
5570
property_reference * ref ;
5545
5571
zend_property_info * prop_info ;
5546
5572
zval * prop ;
5547
- zend_class_entry * ce ;
5548
5573
5549
5574
if (zend_parse_parameters_none () == FAILURE ) {
5550
5575
RETURN_THROWS ();
@@ -5558,15 +5583,7 @@ ZEND_METHOD(reflection_property, hasDefaultValue)
5558
5583
RETURN_FALSE ;
5559
5584
}
5560
5585
5561
- ce = prop_info -> ce ;
5562
-
5563
- if ((prop_info -> flags & ZEND_ACC_STATIC ) != 0 ) {
5564
- prop = & ce -> default_static_members_table [prop_info -> offset ];
5565
- ZVAL_DEINDIRECT (prop );
5566
- } else {
5567
- prop = & ce -> default_properties_table [OBJ_PROP_TO_NUM (prop_info -> offset )];
5568
- }
5569
-
5586
+ prop = property_get_default (prop_info );
5570
5587
RETURN_BOOL (!Z_ISUNDEF_P (prop ));
5571
5588
}
5572
5589
/* }}} */
@@ -5579,7 +5596,6 @@ ZEND_METHOD(reflection_property, getDefaultValue)
5579
5596
property_reference * ref ;
5580
5597
zend_property_info * prop_info ;
5581
5598
zval * prop ;
5582
- zend_class_entry * ce ;
5583
5599
5584
5600
if (zend_parse_parameters_none () == FAILURE ) {
5585
5601
RETURN_THROWS ();
@@ -5593,15 +5609,7 @@ ZEND_METHOD(reflection_property, getDefaultValue)
5593
5609
return ; // throw exception?
5594
5610
}
5595
5611
5596
- ce = prop_info -> ce ;
5597
-
5598
- if ((prop_info -> flags & ZEND_ACC_STATIC ) != 0 ) {
5599
- prop = & ce -> default_static_members_table [prop_info -> offset ];
5600
- ZVAL_DEINDIRECT (prop );
5601
- } else {
5602
- prop = & ce -> default_properties_table [OBJ_PROP_TO_NUM (prop_info -> offset )];
5603
- }
5604
-
5612
+ prop = property_get_default (prop_info );
5605
5613
if (Z_ISUNDEF_P (prop )) {
5606
5614
return ;
5607
5615
}
@@ -5613,7 +5621,7 @@ ZEND_METHOD(reflection_property, getDefaultValue)
5613
5621
/* this is necessary to make it able to work with default array
5614
5622
* properties, returned to user */
5615
5623
if (Z_TYPE_P (return_value ) == IS_CONSTANT_AST ) {
5616
- if (UNEXPECTED (zval_update_constant_ex (return_value , ce ) != SUCCESS )) {
5624
+ if (UNEXPECTED (zval_update_constant_ex (return_value , prop_info -> ce ) != SUCCESS )) {
5617
5625
RETURN_THROWS ();
5618
5626
}
5619
5627
}
0 commit comments