PHP Sample Code
classslash_log {ConstEMERGENCY =1;ConstALERT =2;ConstCRITICAL =3;ConstFATAL =3;ConstERROR =4;ConstWARN =5;ConstNOTICE =6;ConstINFO =7;ConstDEBUG =8; PublicStatic$levels=Array( Self:: EMERGENCY =1, Self:: ALERT =2, Self:: CRITICAL =3, Self:: FATAL =3, Self:: ERROR =4, Self:: WARN =5, Self:: NOTICE =6, Self:: INFO =7, Self::D Ebug =8, );}
Code implemented with PHP extensions
Zend_class_entry CE; Slash_init_class_entry (CE, Slash_cn_log, slash_log_methods); slash_log_ce = Zend_register_internal_class (&ce TSRMLS_CC);//{ {{log levelZend_declare_class_constant_long (Slash_log_ce, Zend_strl (sl_emergency_k), Sl_emergency_v TSRMLS_CC); zend_declare_ Class_constant_long (Slash_log_ce, Zend_strl (sl_alert_k), Sl_alert_v tsrmls_cc); Zend_declare_class_constant_long ( Slash_log_ce, Zend_strl (sl_critical_k), Sl_critical_v tsrmls_cc); Zend_declare_class_constant_long (Slash_log_ce, Zend_strl (Sl_error_k), Sl_error_v tsrmls_cc); Zend_declare_class_constant_long (Slash_log_ce, ZEND_STRL (SL_WARN_K), Sl_warn_v tsrmls_cc); Zend_declare_class_constant_long (Slash_log_ce, Zend_strl (Sl_notice_k), SL_NOTICE_V TSRMLS_CC) ; Zend_declare_class_constant_long (Slash_log_ce, Zend_strl (sl_info_k), Sl_info_v tsrmls_cc); Zend_declare_class_ Constant_long (Slash_log_ce, Zend_strl (sl_debug_k), Sl_debug_v tsrmls_cc);// }}}//{{{} static property arrayZend_declare_property_null (Slash_log_ce, Zend_strl (sl_p_levels), zend_acc_public| Zend_acc_static tsrmls_cc); Zval *levels; Make_std_zval (levels); Array_init (levels); Add_index_stringl (Levels, Sl_emergency_v, Zend_strl (SL_EMERGENCY_K),0); Add_index_stringl (Levels, Sl_alert_v, Zend_strl (Sl_alert_k),0); Add_index_stringl (Levels, Sl_critical_v, Zend_strl (Sl_critical_k),0); Add_index_stringl (Levels, Sl_error_v, Zend_strl (Sl_error_k),0); Add_index_stringl (Levels, Sl_warn_v, Zend_strl (Sl_warn_k),0); Add_index_stringl (Levels, Sl_notice_v, Zend_strl (Sl_notice_k),0); Add_index_stringl (Levels, Sl_info_v, Zend_strl (Sl_info_k),0); Add_index_stringl (Levels, Sl_debug_v, Zend_strl (Sl_debug_k),0); Zend_update_static_property (Slash_log_ce, Zend_strl (sl_p_levels), levels tsrmls_cc);// }}}
The problem of attention
Because in the Notes (1), the extension has no way to initialize the array properties directly, so here we define a static property initialized to Null (ZEND_DECLARE_PROPERTY_NULL), then modify (zend_update_static_ property) The value of this attribute is the corresponding array, which achieves the effect of public static $array.
The corresponding variable name is defined by the macro, so you directly copy the code is not able to compile through, welcome to communicate
The above describes the PHP extension development Note (3) class static array attribute definition, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.