码迷,mamicode.com
首页 > Web开发 > 详细

php扩展开发-常量

时间:2016-12-31 19:00:16      阅读:305      评论:0      收藏:0      [点我收藏+]

标签:constant   height   1.5   style   开发   ons   typedef   过程   定义   

//常量在内核中的结构
typedef struct _zend_constant {
    zval value;
    int flags;
    char *name;
    uint name_len;
    int module_number;
} zend_constant;
//常量注册的宏定义
#define
REGISTER_NULL_CONSTANT(name, flags) zend_register_null_constant((name), sizeof(name), (flags), module_number TSRMLS_CC) #define REGISTER_BOOL_CONSTANT(name, bval, flags) zend_register_bool_constant((name), sizeof(name), (bval), (flags), module_number TSRMLS_CC) #define REGISTER_LONG_CONSTANT(name, lval, flags) zend_register_long_constant((name), sizeof(name), (lval), (flags), module_number TSRMLS_CC) #define REGISTER_DOUBLE_CONSTANT(name, dval, flags) zend_register_double_constant((name), sizeof(name), (dval), (flags), module_number TSRMLS_CC) #define REGISTER_STRING_CONSTANT(name, str, flags) zend_register_string_constant((name), sizeof(name), (str), (flags), module_number TSRMLS_CC) #define REGISTER_STRINGL_CONSTANT(name, str, len, flags) zend_register_stringl_constant((name), sizeof(name), (str), (len), (flags), module_number TSRMLS_CC)
//在MINIT函数中定义常量
//参数说明:
//1,常量名称,此处只能是字符串,不能是变量
//2,常量的值
//3,常量的属性,对应结构体
zend_constant的int flags。CONST_CS表示区分大小写,CONST_PERSISTENT表示在php运行过程中,长期存在
PHP_MINIT_FUNCTION(myext)
{
   REGISTER_STRING_CONSTANT("MYEXT_VERSION",PHP_MYEXT_VERSION,CONST_CS|CONST_PERSISTENT);
    REGISTER_LONG_CONSTANT("MYEXT_LONG_ZERO",0,CONST_CS|CONST_PERSISTENT);
    return SUCCESS;
}
/*

var_dump(MYEXT_VERSION);
var_dump(MYEXT_LONG_ZERO);

 

string(3) "1.0"

int(0)

*/

 

php扩展开发-常量

标签:constant   height   1.5   style   开发   ons   typedef   过程   定义   

原文地址:http://www.cnblogs.com/wuhen781/p/6239639.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!