1--TEST-- 2Test session_encode() function : basic functionality 3--INI-- 4serialize_precision=100 5--SKIPIF-- 6<?php include('skipif.inc'); ?> 7--FILE-- 8<?php 9 10ob_start(); 11 12/* 13 * Prototype : string session_encode(void) 14 * Description : Encodes the current session data as a string 15 * Source code : ext/session/session.c 16 */ 17 18echo "*** Testing session_encode() : basic functionality ***\n"; 19 20// Get an unset variable 21$unset_var = 10; 22unset($unset_var); 23 24class classA 25{ 26 public function __toString() { 27 return "Hello World!"; 28 } 29} 30 31$heredoc = <<<EOT 32Hello World! 33EOT; 34 35$fp = fopen(__FILE__, "r"); 36 37// Unexpected values to be passed as arguments 38$inputs = array( 39 40 // Integer data 41/*1*/ 0, 42 1, 43 12345, 44 -2345, 45 46 // Float data 47/*5*/ 10.5, 48 -10.5, 49 12.3456789000e10, 50 12.3456789000E-10, 51 .5, 52 53 // Null data 54/*10*/ NULL, 55 null, 56 57 // Boolean data 58/*12*/ true, 59 false, 60 TRUE, 61 FALSE, 62 63 // Empty strings 64/*16*/ "", 65 '', 66 67 // Invalid string data 68/*18*/ "Nothing", 69 'Nothing', 70 $heredoc, 71 72 // Object data 73/*21*/ new classA(), 74 75 // Undefined data 76/*22*/ @$undefined_var, 77 78 // Unset data 79/*23*/ @$unset_var, 80 81 // Resource variable 82/*24*/ $fp 83); 84 85var_dump(session_start()); 86$iterator = 1; 87foreach($inputs as $input) { 88 echo "\n-- Iteration $iterator --\n"; 89 $_SESSION["data"] = $input; 90 var_dump(session_encode()); 91 $iterator++; 92}; 93 94var_dump(session_destroy()); 95fclose($fp); 96echo "Done"; 97ob_end_flush(); 98?> 99--EXPECTF-- 100*** Testing session_encode() : basic functionality *** 101bool(true) 102 103-- Iteration 1 -- 104string(9) "data|i:0;" 105 106-- Iteration 2 -- 107string(9) "data|i:1;" 108 109-- Iteration 3 -- 110string(13) "data|i:12345;" 111 112-- Iteration 4 -- 113string(13) "data|i:-2345;" 114 115-- Iteration 5 -- 116string(12) "data|d:10.5;" 117 118-- Iteration 6 -- 119string(13) "data|d:-10.5;" 120 121-- Iteration 7 -- 122string(20) "data|d:123456789000;" 123 124-- Iteration 8 -- 125string(%d) "data|d:1.2345678899999999145113427164344339914681114578343112953007221221923828125E-9;" 126 127-- Iteration 9 -- 128string(11) "data|d:0.5;" 129 130-- Iteration 10 -- 131string(7) "data|N;" 132 133-- Iteration 11 -- 134string(7) "data|N;" 135 136-- Iteration 12 -- 137string(9) "data|b:1;" 138 139-- Iteration 13 -- 140string(9) "data|b:0;" 141 142-- Iteration 14 -- 143string(9) "data|b:1;" 144 145-- Iteration 15 -- 146string(9) "data|b:0;" 147 148-- Iteration 16 -- 149string(12) "data|s:0:"";" 150 151-- Iteration 17 -- 152string(12) "data|s:0:"";" 153 154-- Iteration 18 -- 155string(19) "data|s:7:"Nothing";" 156 157-- Iteration 19 -- 158string(19) "data|s:7:"Nothing";" 159 160-- Iteration 20 -- 161string(25) "data|s:12:"Hello World!";" 162 163-- Iteration 21 -- 164string(22) "data|O:6:"classA":0:{}" 165 166-- Iteration 22 -- 167string(7) "data|N;" 168 169-- Iteration 23 -- 170string(7) "data|N;" 171 172-- Iteration 24 -- 173string(9) "data|i:0;" 174bool(true) 175Done 176 177