@@ -3736,6 +3736,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
37363736 bool owned = 1 ;
37373737 bool persistent = 0 ;
37383738 bool is_const = 0 ;
3739+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
37393740 zend_ffi_flags flags = ZEND_FFI_FLAG_OWNED ;
37403741
37413742 ZEND_FFI_VALIDATE_API_RESTRICTION ();
@@ -3746,6 +3747,13 @@ ZEND_METHOD(FFI, new) /* {{{ */
37463747 Z_PARAM_BOOL (persistent )
37473748 ZEND_PARSE_PARAMETERS_END ();
37483749
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+
37493757 if (!owned ) {
37503758 flags &= ~ZEND_FFI_FLAG_OWNED ;
37513759 }
@@ -3757,7 +3765,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
37573765 if (type_def ) {
37583766 zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
37593767
3760- if (Z_TYPE ( EX ( This )) == IS_OBJECT ) {
3768+ if (! is_static_call ) {
37613769 zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
37623770 FFI_G (symbols ) = ffi -> symbols ;
37633771 FFI_G (tags ) = ffi -> tags ;
@@ -3770,7 +3778,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
37703778
37713779 if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
37723780 zend_ffi_type_dtor (dcl .type );
3773- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3781+ if (is_static_call ) {
37743782 if (FFI_G (tags )) {
37753783 zend_hash_destroy (FFI_G (tags ));
37763784 efree (FFI_G (tags ));
@@ -3790,7 +3798,7 @@ ZEND_METHOD(FFI, new) /* {{{ */
37903798 is_const = 1 ;
37913799 }
37923800
3793- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3801+ if (is_static_call ) {
37943802 if (FFI_G (tags )) {
37953803 zend_ffi_tags_cleanup (& dcl );
37963804 }
@@ -3886,6 +3894,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
38863894 zend_ffi_type * old_type , * type , * type_ptr ;
38873895 zend_ffi_cdata * old_cdata , * cdata ;
38883896 bool is_const = 0 ;
3897+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
38893898 zval * zv , * arg ;
38903899 void * ptr ;
38913900
@@ -3895,13 +3904,20 @@ ZEND_METHOD(FFI, cast) /* {{{ */
38953904 Z_PARAM_ZVAL (zv )
38963905 ZEND_PARSE_PARAMETERS_END ();
38973906
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+
38983914 arg = zv ;
38993915 ZVAL_DEREF (zv );
39003916
39013917 if (type_def ) {
39023918 zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
39033919
3904- if (Z_TYPE ( EX ( This )) == IS_OBJECT ) {
3920+ if (! is_static_call ) {
39053921 zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
39063922 FFI_G (symbols ) = ffi -> symbols ;
39073923 FFI_G (tags ) = ffi -> tags ;
@@ -3914,7 +3930,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
39143930
39153931 if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
39163932 zend_ffi_type_dtor (dcl .type );
3917- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3933+ if (is_static_call ) {
39183934 if (FFI_G (tags )) {
39193935 zend_hash_destroy (FFI_G (tags ));
39203936 efree (FFI_G (tags ));
@@ -3934,7 +3950,7 @@ ZEND_METHOD(FFI, cast) /* {{{ */
39343950 is_const = 1 ;
39353951 }
39363952
3937- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
3953+ if (is_static_call ) {
39383954 if (FFI_G (tags )) {
39393955 zend_ffi_tags_cleanup (& dcl );
39403956 }
@@ -4061,13 +4077,21 @@ ZEND_METHOD(FFI, type) /* {{{ */
40614077 zend_ffi_ctype * ctype ;
40624078 zend_ffi_dcl dcl = ZEND_FFI_ATTR_INIT ;
40634079 zend_string * type_def ;
4080+ bool is_static_call = Z_TYPE (EX (This )) != IS_OBJECT ;
40644081
40654082 ZEND_FFI_VALIDATE_API_RESTRICTION ();
40664083 ZEND_PARSE_PARAMETERS_START (1 , 1 )
40674084 Z_PARAM_STR (type_def );
40684085 ZEND_PARSE_PARAMETERS_END ();
40694086
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 ) {
40714095 zend_ffi * ffi = (zend_ffi * )Z_OBJ (EX (This ));
40724096 FFI_G (symbols ) = ffi -> symbols ;
40734097 FFI_G (tags ) = ffi -> tags ;
@@ -4080,7 +4104,7 @@ ZEND_METHOD(FFI, type) /* {{{ */
40804104
40814105 if (zend_ffi_parse_type (ZSTR_VAL (type_def ), ZSTR_LEN (type_def ), & dcl ) == FAILURE ) {
40824106 zend_ffi_type_dtor (dcl .type );
4083- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
4107+ if (is_static_call ) {
40844108 if (FFI_G (tags )) {
40854109 zend_hash_destroy (FFI_G (tags ));
40864110 efree (FFI_G (tags ));
@@ -4095,7 +4119,7 @@ ZEND_METHOD(FFI, type) /* {{{ */
40954119 return ;
40964120 }
40974121
4098- if (Z_TYPE ( EX ( This )) != IS_OBJECT ) {
4122+ if (is_static_call ) {
40994123 if (FFI_G (tags )) {
41004124 zend_ffi_tags_cleanup (& dcl );
41014125 }
0 commit comments