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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: zegenie at gmail dot com
New email:
PHP Version: OS:

 

 [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
 [2020-08-10 03:09 UTC] webmasteralexo at gmail dot com
The documentation for ob_get_status() seems to be incomplete and out of date.

The array no longer has "status," "del" or "size" keys. The array has "flags" and "buffer_size" keys.

The "type" key in the manual refers to constants PHP_OUTPUT_HANDLER_INTERNAL and PHP_OUTPUT_HANDLER_USER which don't exist and it is not explained what they represent.

The "flags" key uses the constants PHP_OUTPUT_HANDLER_CLEANABLE, PHP_OUTPUT_HANDLER_FLUSHABLE and PHP_OUTPUT_HANDLER_REMOVABLE as flag, but there are some other flags which don't have constants or I was unable to identify which ones they use. Flag 0x1 seems to indicate that a user-defined function was given to ob_start(). Flags 0x1000 and 0x4000 are active if ob_flush() or ob_clean() were called.

The PHP_OUTPUT_HANDLER_START, PHP_OUTPUT_HANDLER_WRITE and PHP_OUTPUT_HANDLER_FINAL flags don't seem to be represented in the data returned by ob_get_status().
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Oct 20 01:01:23 2020 UTC