Re: Access to $_SERVER from engine

From: Date: Fri, 09 Dec 2005 16:14:20 +0000
Subject: Re: Access to $_SERVER from engine
References: 1 2  Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3337@lists.php.net to get a copy of this message
I use the following procedure, but there might be a better approach: /* {{{ zval *http_get_server_var_ex(char *, size_t) */ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC) { zval **hsv; zval **var; if (SUCCESS != zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &hsv)) { return NULL; } if (SUCCESS != zend_hash_find(Z_ARRVAL_PP(hsv), (char *) key, key_size, (void **) &var)) { return NULL; } if (check && !(Z_STRVAL_PP(var) && Z_STRLEN_PP(var))) { return NULL; } return *var; } /* }}} */ Mike-
On the one hand you can check some of the sapi structs described in main/SAPI.h, but as far as your function goes, you should be type checking
the fetched values.  If someone's called: $_SERVER = false;    or $_SERVER['SOME_KEY'] = 123.45;    prior to your function being called, it could cause problems....
Or maybe you're doing that in the activate stage where you can make those assumptions.... -Sara

« previous php.pecl.dev (#3337) next »