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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 + 35 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 06:01:28 2024 UTC