1 zend_parse_parameters
2 例子: 一般用于判断参数
3 *******************
4 1个参数
5 if (zend_parse_parameters(ZEND_NUM_ARGS(), "z|z",¶m1) == FAILURE) {
6 RETURN_FALSE;
7 }
8 #2个参数
9 if( zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz", &age, &area) == FAILURE )
10 {
11 printf("Error\n");
12 RETURN_NULL();
13 }
14
15 | 表示 竖杠前面的参数必须传 后面的参数可以不填写。 但是如果定义2个参数必须填写2个参数
16 #第二个参数是对后边紧跟的参数的类型的限制。
17 备注:
18 参数 代表着的类型
19 b Boolean
20 l Integer 整型
21 d Floating point 浮点型
22 s String 字符串
23 r Resource 资源
24 a Array 数组
25 o Object instance 对象
26 O Object instance of a specified type 特定类型的对象
27 z Non-specific zval 任意类型~
28 Z zval**类型
29 f 表示函数、方法名称
30 *******************
31
32 参数1: ZEND_NUM_ARGS() 参数的个数
33 紧接着
34
35
36 # 声明参数模块
37 //开始参数块定义,pass_rest_by_reference为1时,强制所有参数为引用类型
38 //1表示1个参数
39 ZEND_BEGIN_ARG_INFO(name, pass_rest_by_reference,0,1)
40 //由于这里规定一个参数所有 注释掉第二个。
41 ZEND_ARG_INFO(0, setkey1)
42 //ZEND_ARG_INFO(0, setkey2)
43 ZEND_END_ARG_INFO(); //表示参数模块结束
44
45 *****************
46 #更新对象的属性
47 zend_read_property
48 #更新静态对象的属性。
49 zend_update_static_property
50 # 如果对象或者类中没有相关的属性,函数将自动的添加上。
51 zend_update_property(person_ce, getThis(), "config", sizeof("config")-1, array_config TSRMLS_CC); // 一般在构造函数中
52 #意思 :给person类中的config 赋值 值是 array_config getThis意思是这个类
53
54 *****************
55
56
57 #读取对象的属性
58 zend_read_property
59 #读取静态对象的属性
60 zend_read_static_property
61
62 zval *array_config; //定义一个函数
63 //获取person 这个类中的 config 属性。 //sizeof == count();
64 zend_read_property(person_ce, getThis(), "config", sizeof("config")-1, 0, &rv TSRMLS_DC);
65
66
67
68
69 //将person类和方法(doing saying)注册到zend
70 PHP_MINIT_FUNCTION(person)
71 {
72 zend_class_entry ce;
73 INIT_CLASS_ENTRY(ce, "person", person_functions);
74 person_ce = zend_register_internal_class(&ce TSRMLS_CC);
75
76 zend_declare_property_null(person_ce,"saying",strlen("saying"),ZEND_ACC_PUBLIC); //定义saying方法
77 zend_declare_property_null(person_ce,"doing",strlen("doing"),ZEND_ACC_PUBLIC); //定义doing方法
78
79 return SUCCESS;
80 }