Annotation of embedaddon/php/ext/standard/tests/general_functions/debug_zval_dump_v.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test debug_zval_dump() function : usage variations
                      3: --INI--
                      4: allow_call_time_pass_reference=1
                      5: --FILE--
                      6: <?php
                      7: /* Prototype: void debug_zval_dump ( mixed $variable );
                      8:    Description: Dumps a string representation of an internal zend value 
                      9:                 to output.
                     10: */
                     11: 
                     12: echo "*** Testing debug_zval_dump() on functions ***\n";
                     13: echo "--- Variation 1: global variable inside a function ---\n";
                     14: $global_var = 10;  //declaring global variable
                     15: 
                     16: /* function to dump reference count of global variable,$global_var
                     17:    and local variable,$local_var */
                     18: function dump_globalvar( &$local_var ) {
                     19:   global $global_var;
                     20:   echo "\n-- Value of local variable inside dump_globalvar() --\n";
                     21:   debug_zval_dump( $local_var );
                     22:   echo "\n-- Value of global variable inside dump_globalvar() --\n";
                     23:   debug_zval_dump( $global_var );
                     24: }
                     25: /* dump value and reference count of $global_var using debug_zval_dump() */
                     26: echo "\n-- Value of global variable, before calling dump_globalvar() --\n";
                     27: debug_zval_dump( $global_var );
                     28: 
                     29: /* calling function dump_globalvar() to check the reference count of local
                     30:    and global variables inside the function */
                     31: dump_globalvar( $global_var );
                     32: 
                     33: /* dump value and reference count of $global_var after exiting function
                     34:    dump_globalvar();
                     35:    expected: reference count of $global_var should remain the same as
                     36:              before calling dump_globalvar() function */
                     37: echo "\n-- Value of global variable, after exiting dump_globalvar() --\n";
                     38: debug_zval_dump( $global_var );
                     39: 
                     40: echo "\n--- Variation 2: one variable references another ---\n";
                     41: $first_var = 10;
                     42: /* dump value and reference count of $first_var */
                     43: echo "\n-- Value of \$first_var: --\n";
                     44: debug_zval_dump($first_var);
                     45: 
                     46: /* $ref_first_var references $first_var */
                     47: $ref_first_var = &$var_1;
                     48: 
                     49: echo "\n-- Value of \$ref_first_var --\n";
                     50: debug_zval_dump($ref_first_var);
                     51: echo "\n-- Value of \$first_var --\n";
                     52: debug_zval_dump($first_var);
                     53: 
                     54: unset($ref_first_var); 
                     55: 
                     56: /* dump value and reference count of $first_var, $ref_first_var
                     57:    here $ref_first_var is unset */
                     58: echo "\n-- Value of \$ref_first_var --\n";
                     59: debug_zval_dump($ref_first_var);
                     60: echo "\n-- Value of \$first_var --\n";
                     61: debug_zval_dump($first_var);
                     62: 
                     63: echo "\n--- Variation 3: multiple references of variables ---\n";
                     64: $var_1 = 10;
                     65: $var_2 = &$var_1;
                     66: $var_3 = &$var_2;
                     67: echo "\n-- Value of \$var_1: (before referencing) --\n";
                     68: debug_zval_dump($var_1);
                     69: echo "\n-- Value of \$var_2: (referencing var_1) --\n";
                     70: debug_zval_dump($var_2);
                     71: echo "\n-- Value of \$var_3: (referencing var_2) --\n";
                     72: debug_zval_dump($var_3);
                     73: 
                     74: /* unsetting $var_3 */
                     75: unset($var_3);
                     76: echo "\n-- Value of \$var_3: (after unsetting var_3) --\n"; 
                     77: debug_zval_dump($var_3);
                     78: echo "\n-- Value of \$var_2: --\n";
                     79: debug_zval_dump($var_2);
                     80: echo "\n-- Value of \$var_3: --\n";
                     81: debug_zval_dump($var_1);
                     82: 
                     83: /* unsetting $var_1 */
                     84: unset($var_1);
                     85: echo "\n-- Value of \$var_1: (after unsetting variable_1) --\n";
                     86: debug_zval_dump($var_1);
                     87: echo "\n-- Value of \$var_2: --\n";
                     88: debug_zval_dump($var_2);
                     89: 
                     90: echo "\n*** Testing debug_zval_dump() on miscelleneous input arguments ***\n";
                     91: /* unset a variable */
                     92: $unset_var = 10.5;
                     93: unset($unset_var);
                     94: 
                     95: $misc_values = array (
                     96:   /* nulls */
                     97:   NULL,
                     98:   null,
                     99:   
                    100:   /* unset variable */
                    101:   @$unset_var,
                    102: 
                    103:   /* undefined variable */
                    104:   @$undef_var,
                    105: 
                    106:  /* mixed types */
                    107:   @TRUE123,
                    108:   "123string",
                    109:   "string123",
                    110:   "NULLstring"
                    111: );
                    112: /* loop to display the variables and its reference count using
                    113:     debug_zval_dump() */
                    114: $counter = 1;
                    115: foreach( $misc_values as $value ) {
                    116:   echo "-- Iteration $counter --\n";
                    117:   debug_zval_dump( $value );
                    118:   debug_zval_dump( &$value );
                    119:   $counter++;
                    120: }
                    121: 
                    122: echo "Done\n";
                    123: ?>
                    124: 
                    125: --EXPECTF--
                    126: *** Testing debug_zval_dump() on functions ***
                    127: --- Variation 1: global variable inside a function ---
                    128: 
                    129: -- Value of global variable, before calling dump_globalvar() --
                    130: long(10) refcount(2)
                    131: 
                    132: -- Value of local variable inside dump_globalvar() --
                    133: long(10) refcount(1)
                    134: 
                    135: -- Value of global variable inside dump_globalvar() --
                    136: long(10) refcount(1)
                    137: 
                    138: -- Value of global variable, after exiting dump_globalvar() --
                    139: long(10) refcount(2)
                    140: 
                    141: --- Variation 2: one variable references another ---
                    142: 
                    143: -- Value of $first_var: --
                    144: long(10) refcount(2)
                    145: 
                    146: -- Value of $ref_first_var --
                    147: NULL refcount(1)
                    148: 
                    149: -- Value of $first_var --
                    150: long(10) refcount(2)
                    151: 
                    152: -- Value of $ref_first_var --
                    153: 
                    154: Notice: Undefined variable: ref_first_var in %s on line %d
                    155: NULL refcount(1)
                    156: 
                    157: -- Value of $first_var --
                    158: long(10) refcount(2)
                    159: 
                    160: --- Variation 3: multiple references of variables ---
                    161: 
                    162: -- Value of $var_1: (before referencing) --
                    163: long(10) refcount(1)
                    164: 
                    165: -- Value of $var_2: (referencing var_1) --
                    166: long(10) refcount(1)
                    167: 
                    168: -- Value of $var_3: (referencing var_2) --
                    169: long(10) refcount(1)
                    170: 
                    171: -- Value of $var_3: (after unsetting var_3) --
                    172: 
                    173: Notice: Undefined variable: var_3 in %s on line %d
                    174: NULL refcount(1)
                    175: 
                    176: -- Value of $var_2: --
                    177: long(10) refcount(1)
                    178: 
                    179: -- Value of $var_3: --
                    180: long(10) refcount(1)
                    181: 
                    182: -- Value of $var_1: (after unsetting variable_1) --
                    183: 
                    184: Notice: Undefined variable: var_1 in %s on line %d
                    185: NULL refcount(1)
                    186: 
                    187: -- Value of $var_2: --
                    188: long(10) refcount(2)
                    189: 
                    190: *** Testing debug_zval_dump() on miscelleneous input arguments ***
                    191: -- Iteration 1 --
                    192: NULL refcount(3)
                    193: &NULL refcount(2)
                    194: -- Iteration 2 --
                    195: NULL refcount(3)
                    196: &NULL refcount(2)
                    197: -- Iteration 3 --
                    198: NULL refcount(1)
                    199: &NULL refcount(2)
                    200: -- Iteration 4 --
                    201: NULL refcount(1)
                    202: &NULL refcount(2)
                    203: -- Iteration 5 --
                    204: string(7) "TRUE123" refcount(3)
                    205: &string(7) "TRUE123" refcount(2)
                    206: -- Iteration 6 --
                    207: string(9) "123string" refcount(3)
                    208: &string(9) "123string" refcount(2)
                    209: -- Iteration 7 --
                    210: string(9) "string123" refcount(3)
                    211: &string(9) "string123" refcount(2)
                    212: -- Iteration 8 --
                    213: string(10) "NULLstring" refcount(3)
                    214: &string(10) "NULLstring" refcount(2)
                    215: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>