写扩展,离不了访问全局变量像$_POST,$_GET,$_SERVER等,
以下是YAF提供的代码,我把YAF相关的宏,去掉了...
1 /** YAF文档 http://yaf.laruence.com/manual/ **/
2
3
4 zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) {
5 zval **carrier, **ret;
6
7 #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
8 zend_bool jit_initialization = (PG(auto_globals_jit) && !PG(register_globals) && !PG(register_long_arrays));
9 #else
10 zend_bool jit_initialization = PG(auto_globals_jit);
11 #endif
12
13 /* for phpunit test requirements */
14 switch (type) {
15 case TRACK_VARS_POST:
16 case TRACK_VARS_GET:
17 case TRACK_VARS_FILES:
18 case TRACK_VARS_COOKIE:
19 carrier = &PG(http_globals)[type];
20 break;
21 case TRACK_VARS_ENV:
22 if (jit_initialization) {
23 zend_is_auto_global(ZEND_STRL("_ENV") TSRMLS_CC);
24 }
25 carrier = &PG(http_globals)[type];
26 break;
27 case TRACK_VARS_SERVER:
28 if (jit_initialization) {
29 zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
30 }
31 carrier = &PG(http_globals)[type];
32 break;
33 case TRACK_VARS_REQUEST:
34 if (jit_initialization) {
35 zend_is_auto_global(ZEND_STRL("_REQUEST") TSRMLS_CC);
36 }
37 (void)zend_hash_find(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST")-1, (void **)&carrier);
38 break;
39 default:
40 break;
41 }
42
43 if (!carrier || !(*carrier)) {
44 zval *empty;
45 MAKE_STD_ZVAL(empty);
46 ZVAL_NULL(empty);
47 return empty;
48 }
49
50 if (!len) {
51 Z_ADDREF_P(*carrier);
52 return *carrier;
53 }
54
55 if (zend_hash_find(Z_ARRVAL_PP(carrier), name, len + 1, (void **)&ret) == FAILURE) {
56 zval *empty;
57 MAKE_STD_ZVAL(empty);
58 ZVAL_NULL(empty);
59 return empty;
60 }
61
62 Z_ADDREF_P(*ret);
63 return *ret;
64 }
3
4 zval * yaf_request_query(uint type, char * name, uint len TSRMLS_DC) {
5 zval **carrier, **ret;
6
7 #if (PHP_MAJOR_VERSION == 5) && (PHP_MINOR_VERSION < 4)
8 zend_bool jit_initialization = (PG(auto_globals_jit) && !PG(register_globals) && !PG(register_long_arrays));
9 #else
10 zend_bool jit_initialization = PG(auto_globals_jit);
11 #endif
12
13 /* for phpunit test requirements */
14 switch (type) {
15 case TRACK_VARS_POST:
16 case TRACK_VARS_GET:
17 case TRACK_VARS_FILES:
18 case TRACK_VARS_COOKIE:
19 carrier = &PG(http_globals)[type];
20 break;
21 case TRACK_VARS_ENV:
22 if (jit_initialization) {
23 zend_is_auto_global(ZEND_STRL("_ENV") TSRMLS_CC);
24 }
25 carrier = &PG(http_globals)[type];
26 break;
27 case TRACK_VARS_SERVER:
28 if (jit_initialization) {
29 zend_is_auto_global(ZEND_STRL("_SERVER") TSRMLS_CC);
30 }
31 carrier = &PG(http_globals)[type];
32 break;
33 case TRACK_VARS_REQUEST:
34 if (jit_initialization) {
35 zend_is_auto_global(ZEND_STRL("_REQUEST") TSRMLS_CC);
36 }
37 (void)zend_hash_find(&EG(symbol_table), "_REQUEST", sizeof("_REQUEST")-1, (void **)&carrier);
38 break;
39 default:
40 break;
41 }
42
43 if (!carrier || !(*carrier)) {
44 zval *empty;
45 MAKE_STD_ZVAL(empty);
46 ZVAL_NULL(empty);
47 return empty;
48 }
49
50 if (!len) {
51 Z_ADDREF_P(*carrier);
52 return *carrier;
53 }
54
55 if (zend_hash_find(Z_ARRVAL_PP(carrier), name, len + 1, (void **)&ret) == FAILURE) {
56 zval *empty;
57 MAKE_STD_ZVAL(empty);
58 ZVAL_NULL(empty);
59 return empty;
60 }
61
62 Z_ADDREF_P(*ret);
63 return *ret;
64 }