php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62019 ob_get_status returns 'flags' bitmask instead of 'status' array key
Submitted: 2012-05-14 09:01 UTC Modified: 2017-01-28 12:06 UTC
Votes:17
Avg. Score:4.5 ± 0.7
Reproduced:16 of 16 (100.0%)
Same Version:9 (56.2%)
Same OS:15 (93.8%)
From: zegenie at gmail dot com Assigned:
Status: Open Package: Output Control
PHP Version: 5.4.3 OS: Any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-05-14 09:01 UTC] zegenie at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.ob-get-status#refsect1-function.ob-get-status-returnvalues
---
In php 5.4.x, the return value from ob_get_status() no longer contains the 'status' array key. This seems to have been replaced with a 'flags' array key, breaking BC.

Test script:
---------------
<?php

ob_start();
$ob_status = ob_get_status();
echo (array_key_exists('status', $ob_status)) ? "'status' key exists" : "'status' key does not exist\n"
echo (array_key_exists('flags', $ob_status)) ? "'flags' key exists" : "'flags' key does not exist\n"

Expected result:
----------------
'status' key exists
'flags' key does not exist

Actual result:
--------------
'status' key does not exist
'flags' key exists

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-07-02 17:17 UTC] mikemill at gmail dot com
Additionally, the values of the constants seems to be incorrect.

The test of
<?php
ob_start();
print_r(ob_get_status());
echo "PHP_OUTPUT_HANDLER_END:";
var_dump(PHP_OUTPUT_HANDLER_END);

produces

Array
(
    [level] => 1
    [type] => 1
    [status] => 0
    [name] => default output handler
    [del] => 1
)
PHP_OUTPUT_HANDLER_END:int(4)

on PHP 5.3.6

and

Array
(
    [name] => default output handler
    [type] => 0
    [flags] => 112
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 0
)
PHP_OUTPUT_HANDLER_END:int(8)

on PHP 5.4.4
 [2013-10-03 16:04 UTC] ca at lapage dot com
Update for PHP 5.5.4

The doc should say:

#############################
If called without the full_status parameter or with full_status = FALSE a simple array with the following elements is returned:

Array
(
    [name] => myhandler
    [type] => 1
    [flags] => 20593
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 0
)

* name: the first element returned by get_list_handlers()
* type: PHP_OUTPUT_HANDLER_INTERNAL = 0,  PHP_OUTPUT_HANDLER_USER = 1. Note ob_start() without a parameter and output_buffering=on are each type 0.
* flags: type plus additional flags. In the example above, it is the sum of:
** PHP_OUTPUT_HANDLER_USER = 0x0001 = 1
** PHP_OUTPUT_HANDLER_CLEANABLE = 0x0010 = 16
** PHP_OUTPUT_HANDLER_FLUSHABLE = 0x0020 = 32
** PHP_OUTPUT_HANDLER_REMOVABLE = 0x0040 = 64
** PHP_OUTPUT_HANDLER_STARTED = 0x1000 = 4096
** PHP_OUTPUT_HANDLER_PROCESSED = 0x4000 = 16384
* level: 0-based nesting level, one less than get_ob_level()
* chunk_size: parameter in ob_start()
* buffer_size
* buffer_used

In PHP 5.4 and below, it is:

Array
(
    [level] => 1
    [type] => 1
    [status] => 1
    [name] => myhandler
    [del] => 1
)

* level: 1-based nesting level, the same as get_ob_level()
* type: 0 internal, 1 user. The meaning differs from later PHP. For example, ob_start() without a parameter is type 1.
* status: 0 before buffering, 1 while buffering, possibly other values
* name: the first element returned by get_list_handlers()
* del: erase parameter in ob_start()


If called with full_status = TRUE an array with one element for each active output buffer level is returned. The output level is used as key of the top level array and each array element itself is another array holding status information on one active output level.

Array
(
    [0] => Array
        (
            [name] => myhandler
            [type] => 1
            [flags] => 113
            [level] => 0
            [chunk_size] => 0
            [buffer_size] => 16384
            [buffer_used] => 391
        )

    [1] => Array
        (
            [name] => default output handler
            [type] => 0
            [flags] => 20592
            [level] => 1
            [chunk_size] => 0
            [buffer_size] => 16384
            [buffer_used] => 0
        )

)

In PHP 5.4, with full_status = TRUE, the array returned is the same as PHP 5.5.

In PHP 5.3, the return is like:

Array
(
    [0] => Array
        (
            [chunk_size] => 0
            [size] => 40960
            [block_size] => 10240
            [type] => 1
            [status] => 1
            [name] => myhandler
            [del] => 1
        )
    [1] ...

)

In other words, 'flags' is returned in PHP 5.4 when using full_status = TRUE, and in PHP 5.5 always.
##############################


Test script:
---------------
if (ini_get('output_buffering')) {
} elseif (0) {
  ob_start();
} elseif (0) {
  function myhandler($buffer) { return $buffer; }
  ob_start('myhandler');
} elseif (0) {
  ob_start(create_function( '$buffer', 'return $buffer;' ));
} elseif (1) {
  ob_start(function($buffer) { return $buffer; });
}

print_r($x= ob_get_status());
printf("flags=x%x\n", $x['flags']);
ob_flush();
print_r($x= ob_get_status());
printf("flags=x%x\n", $x['flags']);
print_r(ob_get_status());
print_r(ob_get_status(true));

Expected result:
----------------
Array
(
    [name] => Closure::__invoke
    [type] => 1
    [flags] => 113
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 0
)
flags=x71
Array
(
    [name] => Closure::__invoke
    [type] => 1
    [flags] => 20593
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 0
)
flags=x5071
Array
(
    [name] => Closure::__invoke
    [type] => 1
    [flags] => 20593
    [level] => 0
    [chunk_size] => 0
    [buffer_size] => 16384
    [buffer_used] => 180
)
Array
(
    [0] => Array
        (
            [name] => Closure::__invoke
            [type] => 1
            [flags] => 20593
            [level] => 0
            [chunk_size] => 0
            [buffer_size] => 16384
            [buffer_used] => 350
        )

)


Actual result:
--------------
same
 [2013-10-03 16:13 UTC] ca at lapage dot com
Related Doc Bug #65826 for ob_list_handlers()
 [2017-01-28 12:06 UTC] cmb@php.net
-Package: Documentation problem +Package: Output Control
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 10:01:26 2019 UTC