Doc #62019 [Opn->Csd]: ob_get_status returns 'flags' bitmask instead of 'status' array key

[email protected] Fri, 29 Dec 2023 15:43:25 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=62019&edit=1

 ID:                 62019
 Updated by:         [email protected]
 Reported by:        zegenie at gmail dot com
 Summary:            ob_get_status returns 'flags' bitmask instead of
                     'status' array key
-Status:             Open
+Status:             Closed
 Type:               Documentation Problem
 Package:            Output Control
 Operating System:   Any
 PHP Version:        5.4.3
-Assigned To:        
+Assigned To:        girgias
 Block user comment: N
 Private report:     N

 New Comment:

Fixed via https://github.com/php/doc-en/pull/3034


Previous Comments:
------------------------------------------------------------------------
[2020-08-10 03:09:08] 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().

------------------------------------------------------------------------
[2014-11-19 12:14:49] [email protected]

Related To: Bug #64977

------------------------------------------------------------------------
[2013-10-03 16:13:25] ca at lapage dot com

Related Doc Bug #65826 for ob_list_handlers()

------------------------------------------------------------------------
[2013-10-03 16:12:34] ca2 at lapage dot com

Related To: Bug #65826

------------------------------------------------------------------------
[2013-10-03 16:04:24] 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

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=62019


--
Edit this bug report at https://bugs.php.net/bug.php?id=62019&edit=1