@@ -3736,6 +3736,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
3736
3736
bool owned = 1 ;
3737
3737
bool persistent = 0 ;
3738
3738
bool is_const = 0 ;
3739
+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
3739
3740
zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED ;
3740
3741
3741
3742
ZEND_FFI_VALIDATE_API_RESTRICTION ();
@@ -3746,6 +3747,13 @@ ZEND_METHOD(FFI, new) /* {{{ */
3746
3747
Z_PARAM_BOOL (persistent )
3747
3748
ZEND_PARSE_PARAMETERS_END ();
3748
3749
3750
+ if (is_static_call ) {
3751
+ zend_error (E_DEPRECATED , "Calling FFI::new() statically is deprecated" );
3752
+ if (EG (exception )) {
3753
+ RETURN_THROWS ();
3754
+ }
3755
+ }
3756
+
3749
3757
if (!owned ) {
3750
3758
flags &= ~ZEND_FFI_FLAG_OWNED ;
3751
3759
}
@@ -3757,7 +3765,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
3757
3765
if (type_def ) {
3758
3766
zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
3759
3767
3760
- if (Z_TYPE ( EX ( This )) == IS_OBJECT ) {
3768
+ if (! is_static_call ) {
3761
3769
zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
3762
3770
FFI_G (symbols ) = ffi -> symbols ;
3763
3771
FFI_G (tags ) = ffi -> tags ;
@@ -3770,7 +3778,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
3770
3778
3771
3779
if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3772
3780
zend_ffi_type_dtor (dcl .type );
3773
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3781
+ if (is_static_call ) {
3774
3782
if (FFI_G (tags )) {
3775
3783
zend_hash_destroy (FFI_G (tags ));
3776
3784
efree (FFI_G (tags ));
@@ -3790,7 +3798,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
3790
3798
is_const = 1 ;
3791
3799
}
3792
3800
3793
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3801
+ if (is_static_call ) {
3794
3802
if (FFI_G (tags )) {
3795
3803
zend_ffi_tags_cleanup (& dcl );
3796
3804
}
@@ -3886,6 +3894,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3886
3894
zend_ffi_type * old_type , * type , * type_ptr ;
3887
3895
zend_ffi_cdata * old_cdata , * cdata ;
3888
3896
bool is_const = 0 ;
3897
+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
3889
3898
zval * zv , * arg ;
3890
3899
void * ptr ;
3891
3900
@@ -3895,13 +3904,20 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3895
3904
Z_PARAM_ZVAL (zv )
3896
3905
ZEND_PARSE_PARAMETERS_END ();
3897
3906
3907
+ if (is_static_call ) {
3908
+ zend_error (E_DEPRECATED , "Calling FFI::cast() statically is deprecated" );
3909
+ if (EG (exception )) {
3910
+ RETURN_THROWS ();
3911
+ }
3912
+ }
3913
+
3898
3914
arg = zv ;
3899
3915
ZVAL_DEREF (zv );
3900
3916
3901
3917
if (type_def ) {
3902
3918
zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
3903
3919
3904
- if (Z_TYPE ( EX ( This )) == IS_OBJECT ) {
3920
+ if (! is_static_call ) {
3905
3921
zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
3906
3922
FFI_G (symbols ) = ffi -> symbols ;
3907
3923
FFI_G (tags ) = ffi -> tags ;
@@ -3914,7 +3930,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3914
3930
3915
3931
if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
3916
3932
zend_ffi_type_dtor (dcl .type );
3917
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3933
+ if (is_static_call ) {
3918
3934
if (FFI_G (tags )) {
3919
3935
zend_hash_destroy (FFI_G (tags ));
3920
3936
efree (FFI_G (tags ));
@@ -3934,7 +3950,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
3934
3950
is_const = 1 ;
3935
3951
}
3936
3952
3937
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3953
+ if (is_static_call ) {
3938
3954
if (FFI_G (tags )) {
3939
3955
zend_ffi_tags_cleanup (& dcl );
3940
3956
}
@@ -4061,13 +4077,21 @@ ZEND_METHOD(FFI, type) /* {{{ */
4061
4077
zend_ffi_ctype * ctype ;
4062
4078
zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
4063
4079
zend_string * type_def ;
4080
+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
4064
4081
4065
4082
ZEND_FFI_VALIDATE_API_RESTRICTION ();
4066
4083
ZEND_PARSE_PARAMETERS_START (1 , 1 )
4067
4084
Z_PARAM_STR (type_def );
4068
4085
ZEND_PARSE_PARAMETERS_END ();
4069
4086
4070
- if (Z_TYPE (EX (This )) == IS_OBJECT ) {
4087
+ if (is_static_call ) {
4088
+ zend_error (E_DEPRECATED , "Calling FFI::type() statically is deprecated" );
4089
+ if (EG (exception )) {
4090
+ RETURN_THROWS ();
4091
+ }
4092
+ }
4093
+
4094
+ if (!is_static_call ) {
4071
4095
zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
4072
4096
FFI_G (symbols ) = ffi -> symbols ;
4073
4097
FFI_G (tags ) = ffi -> tags ;
@@ -4080,7 +4104,7 @@ ZEND_METHOD(FFI, type) /* {{{ */
4080
4104
4081
4105
if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
4082
4106
zend_ffi_type_dtor (dcl .type );
4083
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
4107
+ if (is_static_call ) {
4084
4108
if (FFI_G (tags )) {
4085
4109
zend_hash_destroy (FFI_G (tags ));
4086
4110
efree (FFI_G (tags ));
@@ -4095,7 +4119,7 @@ ZEND_METHOD(FFI, type) /* {{{ */
4095
4119
return ;
4096
4120
}
4097
4121
4098
- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
4122
+ if (is_static_call ) {
4099
4123
if (FFI_G (tags )) {
4100
4124
zend_ffi_tags_cleanup (& dcl );
4101
4125
}
0 commit comments