We can get ob level. We can get length of current ob stack. But can we reference ob stack at level n? I would really benefit of getting length of the buffer at specific depth.
Suppose an example:
$length = array();
ob_start();
echo "1";
$length[] = ob_get_length(); // length of current stack (depth 1) is 1
ob_end_clean();
ob_start();
echo "11";
ob_start();
echo "2";
$length[] = ob_get_length(); // length of current stack (depth 2) is 1
ob_end_clean();
ob_end_clean();
ob_start();
echo "111";
ob_start();
echo "22";
ob_start();
echo "3";
$length[] = ob_get_length(); // length of current stack (depth 3) is 1
ob_end_clean();
ob_end_clean();
ob_end_clean();
print_r($length);
Output is:
Array
(
[0] => 1
[1] => 1
[2] => 1
)
The length of each most deepest stack is 1. This is as expected.
My app has recursive output generation and some of output stacks have to know the length of parent system-generated stack. I cannot rely on using ob_get_length() right before opening a new stack simply because other people could wrap the generator in their own ob stack. And that will break the app.
Are there any options? Thanks.
EDIT:
To illustrate what I need to get:
ob_start();
echo "111"; // <-- this is the stack of interest
ob_start();
echo "22";
ob_start();
echo "3";
$length[] = ob_get_length(); // length of current stack (depth 3) is 1
$top_stack_len = get_length_of_ob_stack(1); // expected length here should be 3 (strlen("111") == 3)
ob_end_clean();
ob_end_clean();
echo "some more chars to change length of stack 1";
ob_end_clean();
echo $top_stack_len; // I'm expecting to see 3 here.
updated:
You could create a class to handle it.
I believe that this class will be enough to do it let me know if you need futher help.
example: