1--TEST-- 2ob_start(): multiple buffer initialization with a single call, using arrays. 3--FILE-- 4<?php 5/* 6 * proto bool ob_start([ string|array user_function [, int chunk_size [, bool erase]]]) 7 * Function is implemented in main/output.c 8*/ 9 10function f($string) { 11 static $i=0; 12 $i++; 13 $len = strlen($string); 14 return "f[call:$i; len:$len] - $string\n"; 15} 16 17Class C { 18 public $id = 'none'; 19 20 function __construct($id) { 21 $this->id = $id; 22 } 23 24 static function g($string) { 25 static $i=0; 26 $i++; 27 $len = strlen($string); 28 return "C::g[call:$i; len:$len] - $string\n"; 29 } 30 31 function h($string) { 32 static $i=0; 33 $i++; 34 $len = strlen($string); 35 return "C::h[call:$i; len:$len; id:$this->id] - $string\n"; 36 } 37} 38 39function checkAndClean() { 40 print_r(ob_list_handlers()); 41 while (ob_get_level()>0) { 42 ob_end_flush(); 43 } 44} 45 46echo "\n ---> Test arrays: \n"; 47var_dump(ob_start(array("f"))); 48checkAndClean(); 49 50var_dump(ob_start(array("f", "f"))); 51checkAndClean(); 52 53var_dump(ob_start(array("f", "C::g", "f", "C::g"))); 54checkAndClean(); 55 56var_dump(ob_start(array("f", "non_existent", "f"))); 57checkAndClean(); 58 59var_dump(ob_start(array("f", "non_existent", "f", "f"))); 60checkAndClean(); 61 62$c = new c('originalID'); 63var_dump(ob_start(array($c, "h"))); 64checkAndClean(); 65 66var_dump(ob_start(array($c, "h"))); 67$c->id = 'changedID'; 68checkAndClean(); 69 70$c->id = 'changedIDagain'; 71var_dump(ob_start(array('f', 'C::g', array(array($c, "g"), array($c, "h"))))); 72checkAndClean(); 73?> 74--EXPECTF-- 75 76 ---> Test arrays: 77f[call:1; len:34] - bool(true) 78Array 79( 80 [0] => f 81) 82 83f[call:3; len:68] - f[call:2; len:47] - bool(true) 84Array 85( 86 [0] => f 87 [1] => f 88) 89 90 91f[call:5; len:150] - C::g[call:2; len:125] - f[call:4; len:103] - C::g[call:1; len:79] - bool(true) 92Array 93( 94 [0] => f 95 [1] => C::g 96 [2] => f 97 [3] => C::g 98) 99 100 101 102 103f[call:6; len:35] - bool(false) 104Array 105( 106 [0] => f 107) 108 109f[call:7; len:35] - bool(false) 110Array 111( 112 [0] => f 113) 114 115C::h[call:1; len:37; id:originalID] - bool(true) 116Array 117( 118 [0] => C::h 119) 120 121C::h[call:2; len:37; id:changedID] - bool(true) 122Array 123( 124 [0] => C::h 125) 126 127f[call:8; len:175] - C::g[call:4; len:150] - C::g[call:3; len:125] - C::h[call:3; len:82; id:changedIDagain] - bool(true) 128Array 129( 130 [0] => f 131 [1] => C::g 132 [2] => C::g 133 [3] => C::h 134)