Back to index

php5  5.3.10
Classes | Defines | Typedefs | Functions
php_var.h File Reference
#include "ext/standard/php_smart_str_public.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  php_unserialize_data

Defines

#define php_serialize_data_t   HashTable
#define PHP_VAR_SERIALIZE_INIT(var_hash)   zend_hash_init(&(var_hash), 10, NULL, NULL, 0)
#define PHP_VAR_SERIALIZE_DESTROY(var_hash)   zend_hash_destroy(&(var_hash))
#define PHP_VAR_UNSERIALIZE_INIT(var_hash)
#define PHP_VAR_UNSERIALIZE_DESTROY(var_hash)   var_destroy(&(var_hash))
#define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval)   var_replace((var_hash), (ozval), &(nzval))

Typedefs

typedef struct php_unserialize_data

Functions

 PHP_FUNCTION (var_dump)
 PHP_FUNCTION (var_export)
 PHP_FUNCTION (debug_zval_dump)
 PHP_FUNCTION (serialize)
 PHP_FUNCTION (unserialize)
 PHP_FUNCTION (memory_get_usage)
 PHP_FUNCTION (memory_get_peak_usage)
PHPAPI void php_var_dump (zval **struc, int level TSRMLS_DC)
PHPAPI void php_var_export (zval **struc, int level TSRMLS_DC)
PHPAPI void php_var_export_ex (zval **struc, int level, smart_str *buf TSRMLS_DC)
PHPAPI void php_debug_zval_dump (zval **struc, int level TSRMLS_DC)
PHPAPI void php_var_serialize (smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC)
PHPAPI int php_var_unserialize (zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC)
PHPAPI void var_replace (php_unserialize_data_t *var_hash, zval *ozval, zval **nzval)
PHPAPI void var_push_dtor (php_unserialize_data_t *var_hash, zval **val)
PHPAPI void var_destroy (php_unserialize_data_t *var_hash)
PHPAPI zend_class_entry * php_create_empty_class (char *class_name, int len)
static int php_varname_check (char *name, int name_len, zend_bool silent TSRMLS_DC)

Class Documentation

struct php_unserialize_data

Definition at line 43 of file php_var.h.

Class Members
void * first
void * first_dtor

Define Documentation

Definition at line 41 of file php_var.h.

#define PHP_VAR_SERIALIZE_DESTROY (   var_hash)    zend_hash_destroy(&(var_hash))

Definition at line 55 of file php_var.h.

#define PHP_VAR_SERIALIZE_INIT (   var_hash)    zend_hash_init(&(var_hash), 10, NULL, NULL, 0)

Definition at line 53 of file php_var.h.

#define PHP_VAR_UNSERIALIZE_DESTROY (   var_hash)    var_destroy(&(var_hash))

Definition at line 61 of file php_var.h.

#define PHP_VAR_UNSERIALIZE_INIT (   var_hash)
Value:
(var_hash).first = 0; \
       (var_hash).first_dtor = 0

Definition at line 58 of file php_var.h.

#define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED (   var_hash,
  ozval,
  nzval 
)    var_replace((var_hash), (ozval), &(nzval))

Definition at line 68 of file php_var.h.


Typedef Documentation

typedef struct php_unserialize_data

Definition at line 48 of file php_var.h.


Function Documentation

PHPAPI zend_class_entry* php_create_empty_class ( char *  class_name,
int  len 
)
PHPAPI void php_debug_zval_dump ( zval **  struc,
int level  TSRMLS_DC 
)

Definition at line 240 of file var.c.

{
       HashTable *myht = NULL;
       char *class_name;
       zend_uint class_name_len;
       int (*zval_element_dump_func)(zval** TSRMLS_DC, int, va_list, zend_hash_key*);
       int is_temp = 0;

       if (level > 1) {
              php_printf("%*c", level - 1, ' ');
       }

       switch (Z_TYPE_PP(struc)) {
       case IS_BOOL:
              php_printf("%sbool(%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc)?"true":"false", Z_REFCOUNT_PP(struc));
              break;
       case IS_NULL:
              php_printf("%sNULL refcount(%u)\n", COMMON, Z_REFCOUNT_PP(struc));
              break;
       case IS_LONG:
              php_printf("%slong(%ld) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), Z_REFCOUNT_PP(struc));
              break;
       case IS_DOUBLE:
              php_printf("%sdouble(%.*G) refcount(%u)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc), Z_REFCOUNT_PP(struc));
              break;
       case IS_STRING:
              php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
              PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
              php_printf("\" refcount(%u)\n", Z_REFCOUNT_PP(struc));
              break;
       case IS_ARRAY:
              myht = Z_ARRVAL_PP(struc);
              if (myht->nApplyCount > 1) {
                     PUTS("*RECURSION*\n");
                     return;
              }
              php_printf("%sarray(%d) refcount(%u){\n", COMMON, zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc));
              zval_element_dump_func = zval_array_element_dump;
              goto head_done;
       case IS_OBJECT:
              myht = Z_OBJDEBUG_PP(struc, is_temp);
              if (myht && myht->nApplyCount > 1) {
                     PUTS("*RECURSION*\n");
                     return;
              }
              if (Z_OBJ_HANDLER_PP(struc, get_class_name)) {
                     Z_OBJ_HANDLER_PP(struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);
                     php_printf("%sobject(%s)#%d (%d) refcount(%u){\n", COMMON, class_name, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0, Z_REFCOUNT_PP(struc));
                     efree(class_name);
              } else {
                     php_printf("%sobject(unknown class)#%d (%d) refcount(%u){\n", COMMON, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0, Z_REFCOUNT_PP(struc));
              }
              zval_element_dump_func = zval_object_property_dump;
head_done:
              if (myht) {
                     zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) zval_element_dump_func, 1, level, (Z_TYPE_PP(struc) == IS_ARRAY ? 0 : 1));
                     if (is_temp) {
                            zend_hash_destroy(myht);
                            efree(myht);
                     }
              }
              if (level > 1) {
                     php_printf("%*c", level - 1, ' ');
              }
              PUTS("}\n");
              break;
       case IS_RESOURCE: {
              char *type_name;

              type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
              php_printf("%sresource(%ld) of type (%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown", Z_REFCOUNT_PP(struc));
              break;
       }
       default:
              php_printf("%sUNKNOWN:0\n", COMMON);
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( var_dump  )

Definition at line 170 of file var.c.

{
       zval ***args;
       int argc;
       int    i;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
              return;
       }

       for (i = 0; i < argc; i++) {
              php_var_dump(args[i], 1 TSRMLS_CC);
       }
       efree(args);
}

Here is the call graph for this function:

PHP_FUNCTION ( var_export  )

Definition at line 515 of file var.c.

{
       zval *var;
       zend_bool return_output = 0;
       smart_str buf = {0};

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &return_output) == FAILURE) {
              return;
       }

       php_var_export_ex(&var, 1, &buf TSRMLS_CC);
       smart_str_0 (&buf);

       if (return_output) {
              RETVAL_STRINGL(buf.c, buf.len, 1);
       } else {
              PHPWRITE(buf.c, buf.len);
       }
       smart_str_free(&buf);
}

Here is the call graph for this function:

PHP_FUNCTION ( debug_zval_dump  )

Definition at line 322 of file var.c.

{
       zval ***args;
       int argc;
       int    i;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
              return;
       }

       for (i = 0; i < argc; i++) {
              php_debug_zval_dump(args[i], 1 TSRMLS_CC);
       }
       efree(args);
}

Here is the call graph for this function:

PHP_FUNCTION ( serialize  )

Definition at line 892 of file var.c.

{
       zval **struc;
       php_serialize_data_t var_hash;
       smart_str buf = {0};

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &struc) == FAILURE) {
              return;
       }

       Z_TYPE_P(return_value) = IS_STRING;
       Z_STRVAL_P(return_value) = NULL;
       Z_STRLEN_P(return_value) = 0;

       PHP_VAR_SERIALIZE_INIT(var_hash);
       php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
       PHP_VAR_SERIALIZE_DESTROY(var_hash);

       if (buf.c) {
              RETURN_STRINGL(buf.c, buf.len, 0);
       } else {
              RETURN_NULL();
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( unserialize  )

Definition at line 920 of file var.c.

{
       char *buf = NULL;
       int buf_len;
       const unsigned char *p;
       php_unserialize_data_t var_hash;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) {
              RETURN_FALSE;
       }

       if (buf_len == 0) {
              RETURN_FALSE;
       }

       p = (const unsigned char*) buf;
       PHP_VAR_UNSERIALIZE_INIT(var_hash);
       if (!php_var_unserialize(&return_value, &p, p + buf_len, &var_hash TSRMLS_CC)) {
              PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
              zval_dtor(return_value);
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes", (long)((char*)p - buf), buf_len);
              RETURN_FALSE;
       }
       PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
}

Here is the call graph for this function:

PHP_FUNCTION ( memory_get_usage  )

Definition at line 949 of file var.c.

                               {
       zend_bool real_usage = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(zend_memory_usage(real_usage TSRMLS_CC));
}

Here is the call graph for this function:

PHP_FUNCTION ( memory_get_peak_usage  )

Definition at line 962 of file var.c.

                                    {
       zend_bool real_usage = 0;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(zend_memory_peak_usage(real_usage TSRMLS_CC));
}

Here is the call graph for this function:

PHPAPI void php_var_dump ( zval **  struc,
int level  TSRMLS_DC 
)

Definition at line 87 of file var.c.

{
       HashTable *myht;
       char *class_name;
       zend_uint class_name_len;
       int (*php_element_dump_func)(zval** TSRMLS_DC, int, va_list, zend_hash_key*);
       int is_temp;

       if (level > 1) {
              php_printf("%*c", level - 1, ' ');
       }

       switch (Z_TYPE_PP(struc)) {
       case IS_BOOL:
              php_printf("%sbool(%s)\n", COMMON, Z_LVAL_PP(struc) ? "true" : "false");
              break;
       case IS_NULL:
              php_printf("%sNULL\n", COMMON);
              break;
       case IS_LONG:
              php_printf("%sint(%ld)\n", COMMON, Z_LVAL_PP(struc));
              break;
       case IS_DOUBLE:
              php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc));
              break;
       case IS_STRING:
              php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
              PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
              PUTS("\"\n");
              break;
       case IS_ARRAY:
              myht = Z_ARRVAL_PP(struc);
              if (++myht->nApplyCount > 1) {
                     PUTS("*RECURSION*\n");
                     --myht->nApplyCount;
                     return;
              }
              php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht));
              php_element_dump_func = php_array_element_dump;
              is_temp = 0;
              goto head_done;
       case IS_OBJECT:
              myht = Z_OBJDEBUG_PP(struc, is_temp);
              if (myht && ++myht->nApplyCount > 1) {
                     PUTS("*RECURSION*\n");
                     --myht->nApplyCount;
                     return;
              }

              Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);
              php_printf("%sobject(%s)#%d (%d) {\n", COMMON, class_name, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0);
              efree(class_name);
              php_element_dump_func = php_object_property_dump;
head_done:
              if (myht) {
                     zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_element_dump_func, 1, level);
                     --myht->nApplyCount;
                     if (is_temp) {
                            zend_hash_destroy(myht);
                            efree(myht);
                     }
              }
              if (level > 1) {
                     php_printf("%*c", level-1, ' ');
              }
              PUTS("}\n");
              break;
       case IS_RESOURCE: {
              char *type_name;

              type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
              php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown");
              break;
       }
       default:
              php_printf("%sUNKNOWN:0\n", COMMON);
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_var_export ( zval **  struc,
int level  TSRMLS_DC 
)

Definition at line 503 of file var.c.

{
       smart_str buf = {0};
       php_var_export_ex(struc, level, &buf TSRMLS_CC);
       smart_str_0 (&buf);
       PHPWRITE(buf.c, buf.len);
       smart_str_free(&buf);
}

Here is the call graph for this function:

PHPAPI void php_var_export_ex ( zval **  struc,
int  level,
smart_str *buf  TSRMLS_DC 
)

Definition at line 421 of file var.c.

{
       HashTable *myht;
       char *tmp_str, *tmp_str2;
       int tmp_len, tmp_len2;
       char *class_name;
       zend_uint class_name_len;

       switch (Z_TYPE_PP(struc)) {
       case IS_BOOL:
       if (Z_LVAL_PP(struc)) {
              smart_str_appendl(buf, "true", 4);
       } else {
              smart_str_appendl(buf, "false", 5);
       }
              break;
       case IS_NULL:
              smart_str_appendl(buf, "NULL", 4);
              break;
       case IS_LONG:
              smart_str_append_long(buf, Z_LVAL_PP(struc));
              break;
       case IS_DOUBLE:
              tmp_len = spprintf(&tmp_str, 0,"%.*H", (int) EG(precision), Z_DVAL_PP(struc));
              smart_str_appendl(buf, tmp_str, tmp_len);
              efree(tmp_str);
              break;
       case IS_STRING:
              tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\", 2 TSRMLS_CC);
              tmp_str2 = php_str_to_str_ex(tmp_str, tmp_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len2, 0, NULL);

              smart_str_appendc(buf, '\'');
              smart_str_appendl(buf, tmp_str2, tmp_len2);
              smart_str_appendc(buf, '\'');

              efree(tmp_str2);
              efree(tmp_str);
              break;
       case IS_ARRAY:
              myht = Z_ARRVAL_PP(struc);
              if (level > 1) {
                     smart_str_appendc(buf, '\n');
                     buffer_append_spaces(buf, level - 1);
              }
              smart_str_appendl(buf, "array (\n", 8);
              zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_array_element_export, 2, level, buf);

              if (level > 1) {
                     buffer_append_spaces(buf, level - 1);
              }
              smart_str_appendc(buf, ')');

              break;
       case IS_OBJECT:
              myht = Z_OBJPROP_PP(struc);
              if (level > 1) {
                     smart_str_appendc(buf, '\n');
                     buffer_append_spaces(buf, level - 1);
              }
              Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);

              smart_str_appendl(buf, class_name, class_name_len);
              smart_str_appendl(buf, "::__set_state(array(\n", 21);

              efree(class_name);
              if (myht) {
                     zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_object_element_export, 2, level, buf);
              }
              if (level > 1) {
                     buffer_append_spaces(buf, level - 1);
              }
              smart_str_appendl(buf, "))", 2);

              break;
       default:
              smart_str_appendl(buf, "NULL", 4);
              break;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI void php_var_serialize ( smart_str buf,
zval **  struc,
php_serialize_data_t *var_hash  TSRMLS_DC 
)

Here is the caller graph for this function:

PHPAPI int php_var_unserialize ( zval **  rval,
const unsigned char **  p,
const unsigned char *  max,
php_unserialize_data_t *var_hash  TSRMLS_DC 
)

Here is the caller graph for this function:

static int php_varname_check ( char *  name,
int  name_len,
zend_bool silent  TSRMLS_DC 
) [inline, static]

Definition at line 73 of file php_var.h.

{
    if (name_len == sizeof("GLOBALS") - 1 && !memcmp(name, "GLOBALS", sizeof("GLOBALS") - 1)) {
              if (!silent) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted GLOBALS variable overwrite");
              }
        return FAILURE;
    } else if (name[0] == '_' &&
            (
             (name_len == sizeof("_GET") - 1 && !memcmp(name, "_GET", sizeof("_GET") - 1)) ||
             (name_len == sizeof("_POST") - 1 && !memcmp(name, "_POST", sizeof("_POST") - 1)) ||
             (name_len == sizeof("_COOKIE") - 1 && !memcmp(name, "_COOKIE", sizeof("_COOKIE") - 1)) ||
             (name_len == sizeof("_ENV") - 1 && !memcmp(name, "_ENV", sizeof("_ENV") - 1)) ||
             (name_len == sizeof("_SERVER") - 1 && !memcmp(name, "_SERVER", sizeof("_SERVER") - 1)) ||
             (name_len == sizeof("_SESSION") - 1 && !memcmp(name, "_SESSION", sizeof("_SESSION") - 1)) ||
             (name_len == sizeof("_FILES") - 1  && !memcmp(name, "_FILES", sizeof("_FILES") - 1)) ||
             (name_len == sizeof("_REQUEST") -1 && !memcmp(name, "_REQUEST", sizeof("_REQUEST") - 1))
            )
            ) {
              if (!silent) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted super-global (%s) variable overwrite", name);
              }
        return FAILURE;
    } else if (name[0] == 'H' &&
            (
             (name_len == sizeof("HTTP_POST_VARS") - 1 && !memcmp(name, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS") - 1)) ||
             (name_len == sizeof("HTTP_GET_VARS") - 1 && !memcmp(name, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS") - 1)) ||
             (name_len == sizeof("HTTP_COOKIE_VARS") - 1 && !memcmp(name, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS") - 1)) ||
             (name_len == sizeof("HTTP_ENV_VARS") - 1 && !memcmp(name, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS") - 1)) ||
             (name_len == sizeof("HTTP_SERVER_VARS") - 1 && !memcmp(name, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS") - 1)) ||
             (name_len == sizeof("HTTP_SESSION_VARS") - 1 && !memcmp(name, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS") - 1)) ||
             (name_len == sizeof("HTTP_RAW_POST_DATA") - 1 && !memcmp(name, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA") - 1)) ||
             (name_len == sizeof("HTTP_POST_FILES") - 1 && !memcmp(name, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES") - 1))
            )
            ) {
              if (!silent) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted long input array (%s) overwrite", name);
              }
        return FAILURE;
    }
       return SUCCESS;
}

Here is the caller graph for this function:

PHPAPI void var_destroy ( php_unserialize_data_t *  var_hash)

Definition at line 116 of file var_unserializer.c.

{
       void *next;
       long i;
       var_entries *var_hash = var_hashx->first;
       
       while (var_hash) {
              next = var_hash->next;
              efree(var_hash);
              var_hash = next;
       }

       var_hash = var_hashx->first_dtor;
       
       while (var_hash) {
              for (i = 0; i < var_hash->used_slots; i++) {
                     zval_ptr_dtor(&var_hash->data[i]);
              }
              next = var_hash->next;
              efree(var_hash);
              var_hash = next;
       }
}
PHPAPI void var_push_dtor ( php_unserialize_data_t *  var_hash,
zval **  val 
)

Definition at line 58 of file var_unserializer.c.

{
       var_entries *var_hash = var_hashx->first_dtor, *prev = NULL;

       while (var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
              prev = var_hash;
              var_hash = var_hash->next;
       }

       if (!var_hash) {
              var_hash = emalloc(sizeof(var_entries));
              var_hash->used_slots = 0;
              var_hash->next = 0;

              if (!var_hashx->first_dtor)
                     var_hashx->first_dtor = var_hash;
              else
                     prev->next = var_hash;
       }

       Z_ADDREF_PP(rval);
       var_hash->data[var_hash->used_slots++] = *rval;
}

Here is the caller graph for this function:

PHPAPI void var_replace ( php_unserialize_data_t *  var_hash,
zval *  ozval,
zval **  nzval 
)

Definition at line 82 of file var_unserializer.c.

{
       long i;
       var_entries *var_hash = var_hashx->first;
       
       while (var_hash) {
              for (i = 0; i < var_hash->used_slots; i++) {
                     if (var_hash->data[i] == ozval) {
                            var_hash->data[i] = *nzval;
                            /* do not break here */
                     }
              }
              var_hash = var_hash->next;
       }
}