php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33974 ob_list_handlers(): object-based handlers returned incorrectly.
Submitted: 2005-08-03 12:35 UTC Modified: 2005-08-04 13:58 UTC
From: php at koterov dot ru Assigned:
Status: Not a bug Package: Output Control
PHP Version: 4.3.11 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: php at koterov dot ru
New email:
PHP Version: OS:

 

 [2005-08-03 12:35 UTC] php at koterov dot ru
Description:
------------
Seems ob_list_handlers() cannot return handlers represented as object with method names (see ob_start(array(&$obj, 'F'))). It returns them as "ClassName::MethodName", not as array(..., ...).

Reproduce code:
---------------
<?php
class C { function F($s) { return $s; } }
$obj = new C();
ob_start(array(&$obj, 'F'));
$list = ob_list_handlers();
var_dump($list);
?>

Expected result:
----------------
array(1) { [0]=>  array(..., 'F') }
// where "..." is object $obj

Actual result:
--------------
array(1) { [0]=>  string(4) "c::F" }

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-08-03 13:22 UTC] tony2001@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 [2005-08-03 15:35 UTC] php at koterov dot ru
There is nothing said about this behaviour in the documentation:

http://www.php.net/manual/ru/function.ob-list-handlers.php

And - if I cannot trust the result of ob_list_handlers() (I cannot - it returns bogus handler names), is this function necessary at all?
 [2005-08-03 15:46 UTC] tony2001@php.net
This is how the engine stores callbacks names.
ob_list_handlers() has nothing to do with it. 
This functions is for debugging purposes only and there is nothing said in the docs that it should return valid callbacks.
 [2005-08-04 13:49 UTC] php at koterov dot ru
Very strange, because object-based callbacks works fine with ob_start(). So I guess that full callback info is stored somewhere.

OK, debug purpose. But - maybe write it explicitly in documentation? "This function is for debug purposes only. Do not try to use it for manual callback execution - references will be wrong for object-based callbacks."
 [2005-08-04 13:58 UTC] php at koterov dot ru
I'll detalize why do I say all this words. It would be great  to MANUALLY process all output buffers with their callbacks at the end of script - something like this:

foreach (array_reverse(ob_list_handlers()) as $h) {
  $text = ob_get_contents(); ob_end_clean();
  echo call_user_func($h, $text);
}

Why? Very simple: if I let the callbacks to be called automatically, I'll loose ALL errors, warnings and notices in them, because errors are suppress on standard OB callback execution. But, if I call all the callbacks manually (see example above), it's OK with errors.

I use OB callbacks very often, an there are a lot of PHP code in them (e.g. - HTML tag parsing, placeholder substitutions etc.). Callbacks is a very powerful technique, but - almost undebuggable.

Maybe extend ob_get_status(true) adding valid callback references to returned array?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu May 19 18:03:41 2022 UTC