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