PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - var.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 462 489 94.5 %
Date: 2014-07-13 Functions: 23 24 95.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 5                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2013 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Jani Lehtimäki <jkl@njet.net>                               |
      16             :    |          Thies C. Arntzen <thies@thieso.net>                         |
      17             :    |          Sascha Schumann <sascha@schumann.cx>                        |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : /* {{{ includes
      24             : */
      25             : #include <stdio.h>
      26             : #include <stdlib.h>
      27             : #include <errno.h>
      28             : #include "php.h"
      29             : #include "php_string.h"
      30             : #include "php_var.h"
      31             : #include "php_smart_str.h"
      32             : #include "basic_functions.h"
      33             : #include "php_incomplete_class.h"
      34             : 
      35             : #define COMMON (Z_ISREF_PP(struc) ? "&" : "")
      36             : /* }}} */
      37             : 
      38       64047 : static int php_array_element_dump(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
      39             : {
      40             :         int level;
      41             : 
      42       64047 :         level = va_arg(args, int);
      43             : 
      44       64047 :         if (hash_key->nKeyLength == 0) { /* numeric key */
      45       45288 :                 php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
      46             :         } else { /* string key */
      47       18759 :                 php_printf("%*c[\"", level + 1, ' ');
      48       18759 :                 PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
      49       18759 :                 php_printf("\"]=>\n");
      50             :         }
      51       64047 :         php_var_dump(zv, level + 2 TSRMLS_CC);
      52       64047 :         return 0;
      53             : }
      54             : /* }}} */
      55             : 
      56        6928 : static int php_object_property_dump(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
      57             : {
      58             :         int level;
      59             :         char *prop_name, *class_name;
      60             : 
      61        6928 :         level = va_arg(args, int);
      62             : 
      63        6928 :         if (hash_key->nKeyLength == 0) { /* numeric key */
      64          95 :                 php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
      65             :         } else { /* string key */
      66        6833 :                 int unmangle = zend_unmangle_property_name(hash_key->arKey, hash_key->nKeyLength - 1, &class_name, &prop_name);
      67        6833 :                 php_printf("%*c[", level + 1, ' ');
      68             : 
      69        7842 :                 if (class_name && unmangle == SUCCESS) {
      70        1009 :                         if (class_name[0] == '*') {
      71         334 :                                 php_printf("\"%s\":protected", prop_name);
      72             :                         } else {
      73         675 :                                 php_printf("\"%s\":\"%s\":private", prop_name, class_name);
      74             :                         }
      75             :                 } else {
      76        5824 :                         php_printf("\"");
      77        5824 :                         PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
      78        5824 :                         php_printf("\"");
      79             :                 }
      80        6833 :                 ZEND_PUTS("]=>\n");
      81             :         }
      82        6928 :         php_var_dump(zv, level + 2 TSRMLS_CC);
      83        6928 :         return 0;
      84             : }
      85             : /* }}} */
      86             : 
      87      218106 : PHPAPI void php_var_dump(zval **struc, int level TSRMLS_DC) /* {{{ */
      88             : {
      89             :         HashTable *myht;
      90             :         char *class_name;
      91             :         zend_uint class_name_len;
      92             :         int (*php_element_dump_func)(zval** TSRMLS_DC, int, va_list, zend_hash_key*);
      93             :         int is_temp;
      94             : 
      95      218106 :         if (level > 1) {
      96       70975 :                 php_printf("%*c", level - 1, ' ');
      97             :         }
      98             : 
      99      218106 :         switch (Z_TYPE_PP(struc)) {
     100             :         case IS_BOOL:
     101       87666 :                 php_printf("%sbool(%s)\n", COMMON, Z_LVAL_PP(struc) ? "true" : "false");
     102       43832 :                 break;
     103             :         case IS_NULL:
     104       27296 :                 php_printf("%sNULL\n", COMMON);
     105       13648 :                 break;
     106             :         case IS_LONG:
     107      125020 :                 php_printf("%sint(%ld)\n", COMMON, Z_LVAL_PP(struc));
     108       62510 :                 break;
     109             :         case IS_DOUBLE:
     110       12244 :                 php_printf("%sfloat(%.*G)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc));
     111        6122 :                 break;
     112             :         case IS_STRING:
     113      131472 :                 php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
     114       65736 :                 PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
     115       65736 :                 PUTS("\"\n");
     116       65736 :                 break;
     117             :         case IS_ARRAY:
     118       21777 :                 myht = Z_ARRVAL_PP(struc);
     119       21777 :                 if (++myht->nApplyCount > 1) {
     120          57 :                         PUTS("*RECURSION*\n");
     121          57 :                         --myht->nApplyCount;
     122          57 :                         return;
     123             :                 }
     124       43440 :                 php_printf("%sarray(%d) {\n", COMMON, zend_hash_num_elements(myht));
     125       21720 :                 php_element_dump_func = php_array_element_dump;
     126       21720 :                 is_temp = 0;
     127       21720 :                 goto head_done;
     128             :         case IS_OBJECT:
     129        3649 :                 myht = Z_OBJDEBUG_PP(struc, is_temp);
     130        3649 :                 if (myht && ++myht->nApplyCount > 1) {
     131          54 :                         PUTS("*RECURSION*\n");
     132          54 :                         --myht->nApplyCount;
     133          54 :                         return;
     134             :                 }
     135             : 
     136        3595 :                 Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);
     137        7190 :                 php_printf("%sobject(%s)#%d (%d) {\n", COMMON, class_name, Z_OBJ_HANDLE_PP(struc), myht ? zend_hash_num_elements(myht) : 0);
     138        3595 :                 efree(class_name);
     139        3595 :                 php_element_dump_func = php_object_property_dump;
     140             : head_done:
     141       25315 :                 if (myht) {
     142       25306 :                         zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_element_dump_func, 1, level);
     143       25306 :                         --myht->nApplyCount;
     144       25306 :                         if (is_temp) {
     145         214 :                                 zend_hash_destroy(myht);
     146         214 :                                 efree(myht);
     147             :                         }
     148             :                 }
     149       25315 :                 if (level > 1) {
     150        6303 :                         php_printf("%*c", level-1, ' ');
     151             :                 }
     152       25315 :                 PUTS("}\n");
     153       25315 :                 break;
     154             :         case IS_RESOURCE: {
     155             :                 char *type_name;
     156             : 
     157         831 :                 type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
     158        1662 :                 php_printf("%sresource(%ld) of type (%s)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown");
     159         831 :                 break;
     160             :         }
     161             :         default:
     162           0 :                 php_printf("%sUNKNOWN:0\n", COMMON);
     163             :                 break;
     164             :         }
     165             : }
     166             : /* }}} */
     167             : 
     168             : /* {{{ proto void var_dump(mixed var)
     169             :    Dumps a string representation of variable to output */
     170      145626 : PHP_FUNCTION(var_dump)
     171             : {
     172             :         zval ***args;
     173             :         int argc;
     174             :         int     i;
     175             : 
     176      145626 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
     177           1 :                 return;
     178             :         }
     179             : 
     180      292755 :         for (i = 0; i < argc; i++) {
     181      147131 :                 php_var_dump(args[i], 1 TSRMLS_CC);
     182             :         }
     183      145624 :         efree(args);
     184             : }
     185             : /* }}} */
     186             : 
     187         187 : static int zval_array_element_dump(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     188             : {
     189             :         int level;
     190             : 
     191         187 :         level = va_arg(args, int);
     192             : 
     193         187 :         if (hash_key->nKeyLength == 0) { /* numeric key */
     194          77 :                 php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
     195             :         } else { /* string key */
     196             :                 /* XXX: perphaps when we are inside the class we should permit access to
     197             :                  * private & protected values
     198             :                  */
     199         110 :                 if (va_arg(args, int) && hash_key->arKey[0] == '\0') {
     200           0 :                         return 0;
     201             :                 }
     202         110 :                 php_printf("%*c[\"", level + 1, ' ');
     203         110 :                 PHPWRITE(hash_key->arKey, hash_key->nKeyLength - 1);
     204         110 :                 php_printf("\"]=>\n");
     205             :         }
     206         187 :         php_debug_zval_dump(zv, level + 2 TSRMLS_CC);
     207         187 :         return 0;
     208             : }
     209             : /* }}} */
     210             : 
     211         242 : static int zval_object_property_dump(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     212             : {
     213             :         int level;
     214             :         char *prop_name, *class_name;
     215             : 
     216         242 :         level = va_arg(args, int);
     217             : 
     218         242 :         if (hash_key->nKeyLength == 0) { /* numeric key */
     219           0 :                 php_printf("%*c[%ld]=>\n", level + 1, ' ', hash_key->h);
     220             :         } else { /* string key */
     221         242 :                 zend_unmangle_property_name(hash_key->arKey, hash_key->nKeyLength - 1, &class_name, &prop_name);
     222         242 :                 php_printf("%*c[", level + 1, ' ');
     223             : 
     224         242 :                 if (class_name) {
     225          78 :                         if (class_name[0] == '*') {
     226          39 :                                 php_printf("\"%s\":protected", prop_name);
     227             :                         } else {
     228          39 :                                 php_printf("\"%s\":\"%s\":private", prop_name, class_name);
     229             :                         }
     230             :                 } else {
     231         164 :                         php_printf("\"%s\"", prop_name);
     232             :                 }
     233         242 :                 ZEND_PUTS("]=>\n");
     234             :         }
     235         242 :         php_debug_zval_dump(zv, level + 2 TSRMLS_CC);
     236         242 :         return 0;
     237             : }
     238             : /* }}} */
     239             : 
     240         748 : PHPAPI void php_debug_zval_dump(zval **struc, int level TSRMLS_DC) /* {{{ */
     241             : {
     242         748 :         HashTable *myht = NULL;
     243             :         char *class_name;
     244             :         zend_uint class_name_len;
     245             :         int (*zval_element_dump_func)(zval** TSRMLS_DC, int, va_list, zend_hash_key*);
     246         748 :         int is_temp = 0;
     247             : 
     248         748 :         if (level > 1) {
     249         429 :                 php_printf("%*c", level - 1, ' ');
     250             :         }
     251             : 
     252         748 :         switch (Z_TYPE_PP(struc)) {
     253             :         case IS_BOOL:
     254          36 :                 php_printf("%sbool(%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc)?"true":"false", Z_REFCOUNT_PP(struc));
     255          12 :                 break;
     256             :         case IS_NULL:
     257          81 :                 php_printf("%sNULL refcount(%u)\n", COMMON, Z_REFCOUNT_PP(struc));
     258          27 :                 break;
     259             :         case IS_LONG:
     260        1161 :                 php_printf("%slong(%ld) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), Z_REFCOUNT_PP(struc));
     261         387 :                 break;
     262             :         case IS_DOUBLE:
     263         114 :                 php_printf("%sdouble(%.*G) refcount(%u)\n", COMMON, (int) EG(precision), Z_DVAL_PP(struc), Z_REFCOUNT_PP(struc));
     264          38 :                 break;
     265             :         case IS_STRING:
     266         216 :                 php_printf("%sstring(%d) \"", COMMON, Z_STRLEN_PP(struc));
     267         108 :                 PHPWRITE(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc));
     268         216 :                 php_printf("\" refcount(%u)\n", Z_REFCOUNT_PP(struc));
     269         108 :                 break;
     270             :         case IS_ARRAY:
     271         108 :                 myht = Z_ARRVAL_PP(struc);
     272         108 :                 if (myht->nApplyCount > 1) {
     273           2 :                         PUTS("*RECURSION*\n");
     274           2 :                         return;
     275             :                 }
     276         318 :                 php_printf("%sarray(%d) refcount(%u){\n", COMMON, zend_hash_num_elements(myht), Z_REFCOUNT_PP(struc));
     277         106 :                 zval_element_dump_func = zval_array_element_dump;
     278         106 :                 goto head_done;
     279             :         case IS_OBJECT:
     280          66 :                 myht = Z_OBJDEBUG_PP(struc, is_temp);
     281          66 :                 if (myht && myht->nApplyCount > 1) {
     282          24 :                         PUTS("*RECURSION*\n");
     283          24 :                         return;
     284             :                 }
     285          42 :                 if (Z_OBJ_HANDLER_PP(struc, get_class_name)) {
     286          42 :                         Z_OBJ_HANDLER_PP(struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);
     287         126 :                         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));
     288          42 :                         efree(class_name);
     289             :                 } else {
     290           0 :                         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));
     291             :                 }
     292          42 :                 zval_element_dump_func = zval_object_property_dump;
     293             : head_done:
     294         148 :                 if (myht) {
     295         148 :                         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));
     296         148 :                         if (is_temp) {
     297           1 :                                 zend_hash_destroy(myht);
     298           1 :                                 efree(myht);
     299             :                         }
     300             :                 }
     301         148 :                 if (level > 1) {
     302          94 :                         php_printf("%*c", level - 1, ' ');
     303             :                 }
     304         148 :                 PUTS("}\n");
     305         148 :                 break;
     306             :         case IS_RESOURCE: {
     307             :                 char *type_name;
     308             : 
     309           2 :                 type_name = zend_rsrc_list_get_rsrc_type(Z_LVAL_PP(struc) TSRMLS_CC);
     310           6 :                 php_printf("%sresource(%ld) of type (%s) refcount(%u)\n", COMMON, Z_LVAL_PP(struc), type_name ? type_name : "Unknown", Z_REFCOUNT_PP(struc));
     311           2 :                 break;
     312             :         }
     313             :         default:
     314           0 :                 php_printf("%sUNKNOWN:0\n", COMMON);
     315             :                 break;
     316             :         }
     317             : }
     318             : /* }}} */
     319             : 
     320             : /* {{{ proto void debug_zval_dump(mixed var)
     321             :    Dumps a string representation of an internal zend value to output. */
     322         226 : PHP_FUNCTION(debug_zval_dump)
     323             : {
     324             :         zval ***args;
     325             :         int argc;
     326             :         int     i;
     327             : 
     328         226 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "+", &args, &argc) == FAILURE) {
     329           1 :                 return;
     330             :         }
     331             : 
     332         544 :         for (i = 0; i < argc; i++) {
     333         319 :                 php_debug_zval_dump(args[i], 1 TSRMLS_CC);
     334             :         }
     335         225 :         efree(args);
     336             : }
     337             : /* }}} */
     338             : 
     339             : #define buffer_append_spaces(buf, num_spaces) \
     340             :         do { \
     341             :                 char *tmp_spaces; \
     342             :                 int tmp_spaces_len; \
     343             :                 tmp_spaces_len = spprintf(&tmp_spaces, 0,"%*c", num_spaces, ' '); \
     344             :                 smart_str_appendl(buf, tmp_spaces, tmp_spaces_len); \
     345             :                 efree(tmp_spaces); \
     346             :         } while(0);
     347             : 
     348        1067 : static int php_array_element_export(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     349             : {
     350             :         int level;
     351             :         smart_str *buf;
     352             : 
     353        1067 :         level = va_arg(args, int);
     354        1067 :         buf = va_arg(args, smart_str *);
     355             : 
     356        1067 :         if (hash_key->nKeyLength == 0) { /* numeric key */
     357         943 :                 buffer_append_spaces(buf, level+1);
     358         943 :                 smart_str_append_long(buf, (long) hash_key->h);
     359         943 :                 smart_str_appendl(buf, " => ", 4);
     360             :         } else { /* string key */
     361             :                 char *key, *tmp_str;
     362             :                 int key_len, tmp_len;
     363         124 :                 key = php_addcslashes(hash_key->arKey, hash_key->nKeyLength - 1, &key_len, 0, "'\\", 2 TSRMLS_CC);
     364         124 :                 tmp_str = php_str_to_str_ex(key, key_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len, 0, NULL);
     365             : 
     366         124 :                 buffer_append_spaces(buf, level + 1);
     367             : 
     368         124 :                 smart_str_appendc(buf, '\'');
     369         124 :                 smart_str_appendl(buf, tmp_str, tmp_len);
     370         124 :                 smart_str_appendl(buf, "' => ", 5);
     371             : 
     372         124 :                 efree(key);
     373         124 :                 efree(tmp_str);
     374             :         }
     375        1067 :         php_var_export_ex(zv, level + 2, buf TSRMLS_CC);
     376             : 
     377        1063 :         smart_str_appendc(buf, ',');
     378        1063 :         smart_str_appendc(buf, '\n');
     379             : 
     380        1063 :         return 0;
     381             : }
     382             : /* }}} */
     383             : 
     384         377 : static int php_object_element_export(zval **zv TSRMLS_DC, int num_args, va_list args, zend_hash_key *hash_key) /* {{{ */
     385             : {
     386             :         int level;
     387             :         smart_str *buf;
     388             : 
     389         377 :         level = va_arg(args, int);
     390         377 :         buf = va_arg(args, smart_str *);
     391             : 
     392         377 :         buffer_append_spaces(buf, level + 2);
     393         377 :         if (hash_key->nKeyLength != 0) {
     394             :                 char *class_name, /* ignored, but must be passed to unmangle */
     395             :                          *pname,
     396             :                          *pname_esc;
     397             :                 int  pname_esc_len;
     398             :                 
     399         374 :                 zend_unmangle_property_name(hash_key->arKey, hash_key->nKeyLength - 1,
     400             :                                 &class_name, &pname);
     401         374 :                 pname_esc = php_addcslashes(pname, strlen(pname), &pname_esc_len, 0,
     402             :                         "'\\", 2 TSRMLS_CC);
     403             : 
     404         374 :                 smart_str_appendc(buf, '\'');
     405         374 :                 smart_str_appendl(buf, pname_esc, pname_esc_len);
     406         374 :                 smart_str_appendc(buf, '\'');
     407         374 :                 efree(pname_esc);
     408             :         } else {
     409           3 :                 smart_str_append_long(buf, hash_key->h);
     410             :         }
     411             : 
     412         377 :         smart_str_appendl(buf, " => ", 4);
     413         377 :         php_var_export_ex(zv, level + 2, buf TSRMLS_CC);
     414         374 :         smart_str_appendc(buf, ',');
     415         374 :         smart_str_appendc(buf, '\n');
     416             : 
     417         374 :         return 0;
     418             : }
     419             : /* }}} */
     420             : 
     421        2974 : PHPAPI void php_var_export_ex(zval **struc, int level, smart_str *buf TSRMLS_DC) /* {{{ */
     422             : {
     423             :         HashTable *myht;
     424             :         char *tmp_str, *tmp_str2;
     425             :         int tmp_len, tmp_len2;
     426             :         char *class_name;
     427             :         zend_uint class_name_len;
     428             : 
     429        2974 :         switch (Z_TYPE_PP(struc)) {
     430             :         case IS_BOOL:
     431         146 :         if (Z_LVAL_PP(struc)) {
     432         116 :                 smart_str_appendl(buf, "true", 4);
     433             :         } else {
     434          30 :                 smart_str_appendl(buf, "false", 5);
     435             :         }
     436         146 :                 break;
     437             :         case IS_NULL:
     438         155 :                 smart_str_appendl(buf, "NULL", 4);
     439         155 :                 break;
     440             :         case IS_LONG:
     441         676 :                 smart_str_append_long(buf, Z_LVAL_PP(struc));
     442         676 :                 break;
     443             :         case IS_DOUBLE:
     444          90 :                 tmp_len = spprintf(&tmp_str, 0,"%.*H", (int) EG(precision), Z_DVAL_PP(struc));
     445          90 :                 smart_str_appendl(buf, tmp_str, tmp_len);
     446          90 :                 efree(tmp_str);
     447          90 :                 break;
     448             :         case IS_STRING:
     449        1222 :                 tmp_str = php_addcslashes(Z_STRVAL_PP(struc), Z_STRLEN_PP(struc), &tmp_len, 0, "'\\", 2 TSRMLS_CC);
     450        1222 :                 tmp_str2 = php_str_to_str_ex(tmp_str, tmp_len, "\0", 1, "' . \"\\0\" . '", 12, &tmp_len2, 0, NULL);
     451             : 
     452        1222 :                 smart_str_appendc(buf, '\'');
     453        1222 :                 smart_str_appendl(buf, tmp_str2, tmp_len2);
     454        1222 :                 smart_str_appendc(buf, '\'');
     455             : 
     456        1222 :                 efree(tmp_str2);
     457        1222 :                 efree(tmp_str);
     458        1222 :                 break;
     459             :         case IS_ARRAY:
     460         438 :                 myht = Z_ARRVAL_PP(struc);
     461         438 :                 if (level > 1) {
     462          44 :                         smart_str_appendc(buf, '\n');
     463          44 :                         buffer_append_spaces(buf, level - 1);
     464             :                 }
     465         438 :                 smart_str_appendl(buf, "array (\n", 8);
     466         438 :                 zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_array_element_export, 2, level, buf);
     467             : 
     468         433 :                 if (level > 1) {
     469          40 :                         buffer_append_spaces(buf, level - 1);
     470             :                 }
     471         433 :                 smart_str_appendc(buf, ')');
     472             : 
     473         433 :                 break;
     474             :         case IS_OBJECT:
     475         247 :                 myht = Z_OBJPROP_PP(struc);
     476         247 :                 if (level > 1) {
     477         144 :                         smart_str_appendc(buf, '\n');
     478         144 :                         buffer_append_spaces(buf, level - 1);
     479             :                 }
     480         247 :                 Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name, &class_name_len, 0 TSRMLS_CC);
     481             : 
     482         247 :                 smart_str_appendl(buf, class_name, class_name_len);
     483         247 :                 smart_str_appendl(buf, "::__set_state(array(\n", 21);
     484             : 
     485         247 :                 efree(class_name);
     486         247 :                 if (myht) {
     487         247 :                         zend_hash_apply_with_arguments(myht TSRMLS_CC, (apply_func_args_t) php_object_element_export, 2, level, buf);
     488             :                 }
     489         243 :                 if (level > 1) {
     490         141 :                         buffer_append_spaces(buf, level - 1);
     491             :                 }
     492         243 :                 smart_str_appendl(buf, "))", 2);
     493             : 
     494         243 :                 break;
     495             :         default:
     496           0 :                 smart_str_appendl(buf, "NULL", 4);
     497             :                 break;
     498             :         }
     499        2965 : }
     500             : /* }}} */
     501             : 
     502             : /* FOR BC reasons, this will always perform and then print */
     503           0 : PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC) /* {{{ */
     504             : {
     505           0 :         smart_str buf = {0};
     506           0 :         php_var_export_ex(struc, level, &buf TSRMLS_CC);
     507           0 :         smart_str_0 (&buf);
     508           0 :         PHPWRITE(buf.c, buf.len);
     509           0 :         smart_str_free(&buf);
     510           0 : }
     511             : /* }}} */
     512             : 
     513             : /* {{{ proto mixed var_export(mixed var [, bool return])
     514             :    Outputs or returns a string representation of a variable */
     515        1534 : PHP_FUNCTION(var_export)
     516             : {
     517             :         zval *var;
     518        1534 :         zend_bool return_output = 0;
     519        1534 :         smart_str buf = {0};
     520             : 
     521        1534 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|b", &var, &return_output) == FAILURE) {
     522           4 :                 return;
     523             :         }
     524             : 
     525        1530 :         php_var_export_ex(&var, 1, &buf TSRMLS_CC);
     526        1528 :         smart_str_0 (&buf);
     527             : 
     528        1528 :         if (return_output) {
     529        1178 :                 RETVAL_STRINGL(buf.c, buf.len, 1);
     530             :         } else {
     531         350 :                 PHPWRITE(buf.c, buf.len);
     532             :         }
     533        1528 :         smart_str_free(&buf);
     534             : }
     535             : /* }}} */
     536             : 
     537             : static void php_var_serialize_intern(smart_str *buf, zval *struc, HashTable *var_hash TSRMLS_DC);
     538             : 
     539      227261 : static inline int php_add_var_hash(HashTable *var_hash, zval *var, void *var_old TSRMLS_DC) /* {{{ */
     540             : {
     541             :         ulong var_no;
     542             :         char id[32], *p;
     543             :         register int len;
     544             : 
     545             :         /* relies on "(long)" being a perfect hash function for data pointers,
     546             :          * however the actual identity of an object has had to be determined
     547             :          * by its object handle since 5.0. */
     548      359593 :         if ((Z_TYPE_P(var) == IS_OBJECT) && Z_OBJ_HT_P(var)->get_class_entry) {
     549      132332 :                 p = smart_str_print_long(id + sizeof(id) - 1, (long) Z_OBJ_HANDLE_P(var));
     550      132332 :                 *(--p) = 'O';
     551      132332 :                 len = id + sizeof(id) - 1 - p;
     552             :         } else {
     553       94929 :                 p = smart_str_print_long(id + sizeof(id) - 1, (long) var);
     554       94929 :                 len = id + sizeof(id) - 1 - p;
     555             :         }
     556             : 
     557      227261 :         if (var_old && zend_hash_find(var_hash, p, len, var_old) == SUCCESS) {
     558       27690 :                 if (!Z_ISREF_P(var)) {
     559             :                         /* we still need to bump up the counter, since non-refs will
     560             :                          * be counted separately by unserializer */
     561       27621 :                         var_no = -1;
     562       27621 :                         zend_hash_next_index_insert(var_hash, &var_no, sizeof(var_no), NULL);
     563             :                 }
     564       27690 :                 return FAILURE;
     565             :         }
     566             : 
     567             :         /* +1 because otherwise hash will think we are trying to store NULL pointer */
     568      199571 :         var_no = zend_hash_num_elements(var_hash) + 1;
     569      199571 :         zend_hash_add(var_hash, p, len, &var_no, sizeof(var_no), NULL);
     570      199571 :         return SUCCESS;
     571             : }
     572             : /* }}} */
     573             : 
     574      138745 : static inline void php_var_serialize_long(smart_str *buf, long val) /* {{{ */
     575             : {
     576      138745 :         smart_str_appendl(buf, "i:", 2);
     577      138745 :         smart_str_append_long(buf, val);
     578      138745 :         smart_str_appendc(buf, ';');
     579      138745 : }
     580             : /* }}} */
     581             : 
     582       41775 : static inline void php_var_serialize_string(smart_str *buf, char *str, int len) /* {{{ */
     583             : {
     584       41775 :         smart_str_appendl(buf, "s:", 2);
     585       41775 :         smart_str_append_long(buf, len);
     586       41775 :         smart_str_appendl(buf, ":\"", 2);
     587       41775 :         smart_str_appendl(buf, str, len);
     588       41775 :         smart_str_appendl(buf, "\";", 2);
     589       41775 : }
     590             : /* }}} */
     591             : 
     592      132259 : static inline zend_bool php_var_serialize_class_name(smart_str *buf, zval *struc TSRMLS_DC) /* {{{ */
     593             : {
     594      132259 :         PHP_CLASS_ATTRIBUTES;
     595             : 
     596      132259 :         PHP_SET_CLASS_ATTRIBUTES(struc);
     597      132259 :         smart_str_appendl(buf, "O:", 2);
     598      132259 :         smart_str_append_long(buf, (int)name_len);
     599      132259 :         smart_str_appendl(buf, ":\"", 2);
     600      132259 :         smart_str_appendl(buf, class_name, name_len);
     601      132259 :         smart_str_appendl(buf, "\":", 2);
     602      132259 :         PHP_CLEANUP_CLASS_ATTRIBUTES();
     603      132259 :         return incomplete_class;
     604             : }
     605             : /* }}} */
     606             : 
     607           6 : static void php_var_serialize_class(smart_str *buf, zval *struc, zval *retval_ptr, HashTable *var_hash TSRMLS_DC) /* {{{ */
     608             : {
     609             :         int count;
     610             :         zend_bool incomplete_class;
     611             : 
     612           6 :         incomplete_class = php_var_serialize_class_name(buf, struc TSRMLS_CC);
     613             :         /* count after serializing name, since php_var_serialize_class_name
     614             :          * changes the count if the variable is incomplete class */
     615           6 :         count = zend_hash_num_elements(HASH_OF(retval_ptr));
     616           6 :         if (incomplete_class) {
     617           0 :                 --count;
     618             :         }
     619           6 :         smart_str_append_long(buf, count);
     620           6 :         smart_str_appendl(buf, ":{", 2);
     621             : 
     622           6 :         if (count > 0) {
     623             :                 char *key;
     624             :                 zval **d, **name;
     625             :                 ulong index;
     626             :                 HashPosition pos;
     627             :                 int i;
     628             :                 zval nval, *nvalp;
     629             :                 HashTable *propers;
     630             : 
     631           4 :                 ZVAL_NULL(&nval);
     632           4 :                 nvalp = &nval;
     633             : 
     634           4 :                 zend_hash_internal_pointer_reset_ex(HASH_OF(retval_ptr), &pos);
     635             : 
     636          10 :                 for (;; zend_hash_move_forward_ex(HASH_OF(retval_ptr), &pos)) {
     637          14 :                         i = zend_hash_get_current_key_ex(HASH_OF(retval_ptr), &key, NULL, &index, 0, &pos);
     638             : 
     639          14 :                         if (i == HASH_KEY_NON_EXISTANT) {
     640           4 :                                 break;
     641             :                         }
     642             : 
     643          10 :                         if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) {
     644           0 :                                 continue;
     645             :                         }
     646          10 :                         zend_hash_get_current_data_ex(HASH_OF(retval_ptr), (void **) &name, &pos);
     647             : 
     648          10 :                         if (Z_TYPE_PP(name) != IS_STRING) {
     649           0 :                                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize.");
     650             :                                 /* we should still add element even if it's not OK,
     651             :                                  * since we already wrote the length of the array before */
     652           0 :                                 smart_str_appendl(buf,"N;", 2);
     653           0 :                                 continue;
     654             :                         }
     655          10 :                         propers = Z_OBJPROP_P(struc);
     656          10 :                         if (zend_hash_find(propers, Z_STRVAL_PP(name), Z_STRLEN_PP(name) + 1, (void *) &d) == SUCCESS) {
     657           4 :                                 php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
     658           4 :                                 php_var_serialize_intern(buf, *d, var_hash TSRMLS_CC);
     659             :                         } else {
     660             :                                 zend_class_entry *ce;
     661           6 :                                 ce = zend_get_class_entry(struc TSRMLS_CC);
     662           6 :                                 if (ce) {
     663             :                                         char *prot_name, *priv_name;
     664             :                                         int prop_name_length;
     665             : 
     666             :                                         do {
     667           6 :                                                 zend_mangle_property_name(&priv_name, &prop_name_length, ce->name, ce->name_length, Z_STRVAL_PP(name), Z_STRLEN_PP(name), ce->type & ZEND_INTERNAL_CLASS);
     668           6 :                                                 if (zend_hash_find(propers, priv_name, prop_name_length + 1, (void *) &d) == SUCCESS) {
     669           2 :                                                         php_var_serialize_string(buf, priv_name, prop_name_length);
     670           2 :                                                         pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS);
     671           2 :                                                         php_var_serialize_intern(buf, *d, var_hash TSRMLS_CC);
     672           2 :                                                         break;
     673             :                                                 }
     674           4 :                                                 pefree(priv_name, ce->type & ZEND_INTERNAL_CLASS);
     675           4 :                                                 zend_mangle_property_name(&prot_name, &prop_name_length, "*", 1, Z_STRVAL_PP(name), Z_STRLEN_PP(name), ce->type & ZEND_INTERNAL_CLASS);
     676           4 :                                                 if (zend_hash_find(propers, prot_name, prop_name_length + 1, (void *) &d) == SUCCESS) {
     677           1 :                                                         php_var_serialize_string(buf, prot_name, prop_name_length);
     678           1 :                                                         pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
     679           1 :                                                         php_var_serialize_intern(buf, *d, var_hash TSRMLS_CC);
     680           1 :                                                         break;
     681             :                                                 }
     682           3 :                                                 pefree(prot_name, ce->type & ZEND_INTERNAL_CLASS);
     683           3 :                                                 php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
     684           3 :                                                 php_var_serialize_intern(buf, nvalp, var_hash TSRMLS_CC);
     685           3 :                                                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "\"%s\" returned as member variable from __sleep() but does not exist", Z_STRVAL_PP(name));
     686             :                                         } while (0);
     687             :                                 } else {
     688           0 :                                         php_var_serialize_string(buf, Z_STRVAL_PP(name), Z_STRLEN_PP(name));
     689           0 :                                         php_var_serialize_intern(buf, nvalp, var_hash TSRMLS_CC);
     690             :                                 }
     691             :                         }
     692          10 :                 }
     693             :         }
     694           6 :         smart_str_appendc(buf, '}');
     695           6 : }
     696             : /* }}} */
     697             : 
     698      227261 : static void php_var_serialize_intern(smart_str *buf, zval *struc, HashTable *var_hash TSRMLS_DC) /* {{{ */
     699             : {
     700             :         int i;
     701             :         ulong *var_already;
     702             :         HashTable *myht;
     703             : 
     704      227261 :         if (var_hash && php_add_var_hash(var_hash, struc, (void *) &var_already TSRMLS_CC) == FAILURE) {
     705       55380 :                 if (Z_ISREF_P(struc)) {
     706          69 :                         smart_str_appendl(buf, "R:", 2);
     707          69 :                         smart_str_append_long(buf, (long)*var_already);
     708          69 :                         smart_str_appendc(buf, ';');
     709          69 :                         return;
     710       27621 :                 } else if (Z_TYPE_P(struc) == IS_OBJECT) {
     711          26 :                         smart_str_appendl(buf, "r:", 2);
     712          26 :                         smart_str_append_long(buf, (long)*var_already);
     713          26 :                         smart_str_appendc(buf, ';');
     714          26 :                         return;
     715             :                 }
     716             :         }
     717             : 
     718      227166 :         switch (Z_TYPE_P(struc)) {
     719             :                 case IS_BOOL:
     720          50 :                         smart_str_appendl(buf, "b:", 2);
     721          50 :                         smart_str_append_long(buf, Z_LVAL_P(struc));
     722          50 :                         smart_str_appendc(buf, ';');
     723          50 :                         return;
     724             : 
     725             :                 case IS_NULL:
     726          89 :                         smart_str_appendl(buf, "N;", 2);
     727          89 :                         return;
     728             : 
     729             :                 case IS_LONG:
     730        5150 :                         php_var_serialize_long(buf, Z_LVAL_P(struc));
     731        5150 :                         return;
     732             : 
     733             :                 case IS_DOUBLE: {
     734             :                                 char *s;
     735             : 
     736          75 :                                 smart_str_appendl(buf, "d:", 2);
     737          75 :                                 s = (char *) safe_emalloc(PG(serialize_precision), 1, MAX_LENGTH_OF_DOUBLE + 1);
     738          75 :                                 php_gcvt(Z_DVAL_P(struc), PG(serialize_precision), '.', 'E', s);
     739          75 :                                 smart_str_appends(buf, s);
     740          75 :                                 smart_str_appendc(buf, ';');
     741          75 :                                 efree(s);
     742          75 :                                 return;
     743             :                         }
     744             : 
     745             :                 case IS_STRING:
     746       14838 :                         php_var_serialize_string(buf, Z_STRVAL_P(struc), Z_STRLEN_P(struc));
     747       14838 :                         return;
     748             : 
     749             :                 case IS_OBJECT: {
     750      132292 :                                 zval *retval_ptr = NULL;
     751             :                                 zval fname;
     752             :                                 int res;
     753      132292 :                                 zend_class_entry *ce = NULL;
     754             : 
     755      132292 :                                 if (Z_OBJ_HT_P(struc)->get_class_entry) {
     756      132292 :                                         ce = Z_OBJCE_P(struc);
     757             :                                 }
     758             : 
     759      132292 :                                 if (ce && ce->serialize != NULL) {
     760             :                                         /* has custom handler */
     761          32 :                                         unsigned char *serialized_data = NULL;
     762             :                                         zend_uint serialized_length;
     763             : 
     764          32 :                                         if (ce->serialize(struc, &serialized_data, &serialized_length, (zend_serialize_data *)var_hash TSRMLS_CC) == SUCCESS) {
     765          27 :                                                 smart_str_appendl(buf, "C:", 2);
     766          27 :                                                 smart_str_append_long(buf, (int)Z_OBJCE_P(struc)->name_length);
     767          27 :                                                 smart_str_appendl(buf, ":\"", 2);
     768          27 :                                                 smart_str_appendl(buf, Z_OBJCE_P(struc)->name, Z_OBJCE_P(struc)->name_length);
     769          27 :                                                 smart_str_appendl(buf, "\":", 2);
     770             : 
     771          27 :                                                 smart_str_append_long(buf, (int)serialized_length);
     772          27 :                                                 smart_str_appendl(buf, ":{", 2);
     773          27 :                                                 smart_str_appendl(buf, serialized_data, serialized_length);
     774          27 :                                                 smart_str_appendc(buf, '}');
     775             :                                         } else {
     776           5 :                                                 smart_str_appendl(buf, "N;", 2);
     777             :                                         }
     778          32 :                                         if (serialized_data) {
     779          27 :                                                 efree(serialized_data);
     780             :                                         }
     781          32 :                                         return;
     782             :                                 }
     783             : 
     784      132260 :                                 if (ce && ce != PHP_IC_ENTRY && zend_hash_exists(&ce->function_table, "__sleep", sizeof("__sleep"))) {
     785          14 :                                         INIT_PZVAL(&fname);
     786          14 :                                         ZVAL_STRINGL(&fname, "__sleep", sizeof("__sleep") - 1, 0);
     787          14 :                                         res = call_user_function_ex(CG(function_table), &struc, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
     788             : 
     789          14 :                                         if (res == SUCCESS && !EG(exception)) {
     790           7 :                                                 if (retval_ptr) {
     791           7 :                                                         if (HASH_OF(retval_ptr)) {
     792           6 :                                                                 php_var_serialize_class(buf, struc, retval_ptr, var_hash TSRMLS_CC);
     793             :                                                         } else {
     794           1 :                                                                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "__sleep should return an array only containing the names of instance-variables to serialize");
     795             :                                                                 /* we should still add element even if it's not OK,
     796             :                                                                  * since we already wrote the length of the array before */
     797           1 :                                                                 smart_str_appendl(buf,"N;", 2);
     798             :                                                         }
     799           7 :                                                         zval_ptr_dtor(&retval_ptr);
     800             :                                                 }
     801           7 :                                                 return;
     802             :                                         }
     803             :                                 }
     804             : 
     805      132253 :                                 if (retval_ptr) {
     806           0 :                                         zval_ptr_dtor(&retval_ptr);
     807             :                                 }
     808             :                                 /* fall-through */
     809             :                         }
     810             :                 case IS_ARRAY: {
     811      206922 :                         zend_bool incomplete_class = 0;
     812      206922 :                         if (Z_TYPE_P(struc) == IS_ARRAY) {
     813       74669 :                                 smart_str_appendl(buf, "a:", 2);
     814       74669 :                                 myht = HASH_OF(struc);
     815             :                         } else {
     816      132253 :                                 incomplete_class = php_var_serialize_class_name(buf, struc TSRMLS_CC);
     817      132253 :                                 myht = Z_OBJPROP_P(struc);
     818             :                         }
     819             :                         /* count after serializing name, since php_var_serialize_class_name
     820             :                          * changes the count if the variable is incomplete class */
     821      206922 :                         i = myht ? zend_hash_num_elements(myht) : 0;
     822      206922 :                         if (i > 0 && incomplete_class) {
     823           2 :                                 --i;
     824             :                         }
     825      206922 :                         smart_str_append_long(buf, i);
     826      206922 :                         smart_str_appendl(buf, ":{", 2);
     827      206922 :                         if (i > 0) {
     828             :                                 char *key;
     829             :                                 zval **data;
     830             :                                 ulong index;
     831             :                                 uint key_len;
     832             :                                 HashPosition pos;
     833             : 
     834       74766 :                                 zend_hash_internal_pointer_reset_ex(myht, &pos);
     835      160522 :                                 for (;; zend_hash_move_forward_ex(myht, &pos)) {
     836      235288 :                                         i = zend_hash_get_current_key_ex(myht, &key, &key_len, &index, 0, &pos);
     837      235288 :                                         if (i == HASH_KEY_NON_EXISTANT) {
     838       74766 :                                                 break;
     839             :                                         }
     840      160522 :                                         if (incomplete_class && strcmp(key, MAGIC_MEMBER) == 0) {
     841           0 :                                                 continue;
     842             :                                         }
     843             : 
     844      160522 :                                         switch (i) {
     845             :                                                 case HASH_KEY_IS_LONG:
     846      133595 :                                                         php_var_serialize_long(buf, index);
     847      133595 :                                                         break;
     848             :                                                 case HASH_KEY_IS_STRING:
     849       26927 :                                                         php_var_serialize_string(buf, key, key_len - 1);
     850             :                                                         break;
     851             :                                         }
     852             : 
     853             :                                         /* we should still add element even if it's not OK,
     854             :                                          * since we already wrote the length of the array before */
     855      650536 :                                         if (zend_hash_get_current_data_ex(myht, (void **) &data, &pos) != SUCCESS
     856      321044 :                                                 || !data
     857             :                                                 || data == &struc
     858      329492 :                                                 || (Z_TYPE_PP(data) == IS_ARRAY && Z_ARRVAL_PP(data)->nApplyCount > 1)
     859             :                                         ) {
     860           0 :                                                 smart_str_appendl(buf, "N;", 2);
     861             :                                         } else {
     862      160522 :                                                 if (Z_TYPE_PP(data) == IS_ARRAY) {
     863        8448 :                                                         Z_ARRVAL_PP(data)->nApplyCount++;
     864             :                                                 }
     865      160522 :                                                 php_var_serialize_intern(buf, *data, var_hash TSRMLS_CC);
     866      160522 :                                                 if (Z_TYPE_PP(data) == IS_ARRAY) {
     867        8448 :                                                         Z_ARRVAL_PP(data)->nApplyCount--;
     868             :                                                 }
     869             :                                         }
     870      160522 :                                 }
     871             :                         }
     872      206922 :                         smart_str_appendc(buf, '}');
     873      206922 :                         return;
     874             :                 }
     875             :                 default:
     876           3 :                         smart_str_appendl(buf, "i:0;", 4);
     877           3 :                         return;
     878             :         }
     879             : }
     880             : /* }}} */
     881             : 
     882       66729 : PHPAPI void php_var_serialize(smart_str *buf, zval **struc, HashTable *var_hash TSRMLS_DC) /* {{{ */
     883             : {
     884       66729 :         php_var_serialize_intern(buf, *struc, var_hash TSRMLS_CC);
     885       66729 :         smart_str_0(buf);
     886       66729 : }
     887             : /* }}} */
     888             : 
     889             : /* {{{ proto string serialize(mixed variable)
     890             :    Returns a string representation of variable (which can later be unserialized) */
     891       66294 : PHP_FUNCTION(serialize)
     892             : {
     893             :         zval **struc;
     894             :         php_serialize_data_t var_hash;
     895       66294 :         smart_str buf = {0};
     896             : 
     897       66294 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &struc) == FAILURE) {
     898           2 :                 return;
     899             :         }
     900             : 
     901       66292 :         Z_TYPE_P(return_value) = IS_STRING;
     902       66292 :         Z_STRVAL_P(return_value) = NULL;
     903       66292 :         Z_STRLEN_P(return_value) = 0;
     904             : 
     905       66292 :         PHP_VAR_SERIALIZE_INIT(var_hash);
     906       66292 :         php_var_serialize(&buf, struc, &var_hash TSRMLS_CC);
     907       66292 :         PHP_VAR_SERIALIZE_DESTROY(var_hash);
     908             : 
     909       66292 :         if (buf.c) {
     910       66292 :                 RETURN_STRINGL(buf.c, buf.len, 0);
     911             :         } else {
     912           0 :                 RETURN_NULL();
     913             :         }
     914             : }
     915             : /* }}} */
     916             : 
     917             : /* {{{ proto mixed unserialize(string variable_representation)
     918             :    Takes a string representation of variable and recreates it */
     919       66290 : PHP_FUNCTION(unserialize)
     920             : {
     921       66290 :         char *buf = NULL;
     922             :         int buf_len;
     923             :         const unsigned char *p;
     924             :         php_unserialize_data_t var_hash;
     925             : 
     926       66290 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &buf, &buf_len) == FAILURE) {
     927           2 :                 RETURN_FALSE;
     928             :         }
     929             : 
     930       66288 :         if (buf_len == 0) {
     931           0 :                 RETURN_FALSE;
     932             :         }
     933             : 
     934       66288 :         p = (const unsigned char*) buf;
     935       66288 :         PHP_VAR_UNSERIALIZE_INIT(var_hash);
     936       66288 :         if (!php_var_unserialize(&return_value, &p, p + buf_len, &var_hash TSRMLS_CC)) {
     937          16 :                 PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
     938          16 :                 zval_dtor(return_value);
     939          16 :                 php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Error at offset %ld of %d bytes", (long)((char*)p - buf), buf_len);
     940          16 :                 RETURN_FALSE;
     941             :         }
     942       66267 :         PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
     943             : }
     944             : /* }}} */
     945             : 
     946             : /* {{{ proto int memory_get_usage([real_usage])
     947             :    Returns the allocated by PHP memory */
     948          14 : PHP_FUNCTION(memory_get_usage) {
     949          14 :         zend_bool real_usage = 0;
     950             : 
     951          14 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) == FAILURE) {
     952           0 :                 RETURN_FALSE;
     953             :         }
     954             : 
     955          14 :         RETURN_LONG(zend_memory_usage(real_usage TSRMLS_CC));
     956             : }
     957             : /* }}} */
     958             : 
     959             : /* {{{ proto int memory_get_peak_usage([real_usage])
     960             :    Returns the peak allocated by PHP memory */
     961           1 : PHP_FUNCTION(memory_get_peak_usage) {
     962           1 :         zend_bool real_usage = 0;
     963             : 
     964           1 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &real_usage) == FAILURE) {
     965           0 :                 RETURN_FALSE;
     966             :         }
     967             : 
     968           1 :         RETURN_LONG(zend_memory_peak_usage(real_usage TSRMLS_CC));
     969             : }
     970             : /* }}} */
     971             : 
     972             : /*
     973             :  * Local variables:
     974             :  * tab-width: 4
     975             :  * c-basic-offset: 4
     976             :  * End:
     977             :  * vim600: sw=4 ts=4 fdm=marker
     978             :  * vim<600: sw=4 ts=4
     979             :  */

Generated by: LCOV version 1.10

Generated at Sun, 13 Jul 2014 23:57:57 +0000 (8 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.