PHP.nl

ob_list_handlers

ob_list_handlers

List all output handlers in use

array **ob_list_handlers**

Lists all output handlers in use.

This will return an array with the output handlers in use (if any).

If is enabled and no is set, or no callback or null was passed to , is returned. Enabling and setting an is equivalent to passing an to . output_bufferingoutput_handlerob_start``"default output handler"output_bufferingoutput_handlerinternal (built-in) functionob_start

If a was passed to , the of the is returned. If the is an object implementing , the of the object's method is returned. If the is a , is returned. callable``ob_startfully qualified namecallable``callable__invoke()fully qualified name__invoke()callable``Closure``"Closure::__invoke"

Voorbeeld: example

<?php
// using output_buffering=On, no output_handler set
var_dump(ob_list_handlers());
ob_end_flush();

// no callback or null
ob_start();
var_dump(ob_list_handlers());
ob_end_flush();

// anonymous function
ob_start(function($string) { return $string; });
var_dump(ob_list_handlers());
ob_end_flush();

// arrow function
ob_start(fn($string) => $string);
var_dump(ob_list_handlers());
ob_end_flush();

// first class callable
$firstClassCallable = userDefinedFunction(...);

ob_start([$firstClassCallable, '__invoke']);
var_dump(ob_list_handlers());
ob_end_flush();

// internal (built-in) function
ob_start('print_r');
var_dump(ob_list_handlers());
ob_end_flush();

// user-defined function
function userDefinedFunction($string, $flags) { return $string; };

ob_start('userDefinedFunction');
var_dump(ob_list_handlers());
ob_end_flush();

class MyClass {
    public static function staticHandle($string) {
        return $string;
    }

    public static function handle($string) {
        return $string;
    }

    public function __invoke($string) {
        return $string;
    }
}

// class and static method
ob_start(['MyClass','staticHandle']);
var_dump(ob_list_handlers());
ob_end_flush();

// object and non-static method
ob_start([new MyClass,'handle']);
var_dump(ob_list_handlers());
ob_end_flush();

// invokable object
ob_start(new MyClass);
var_dump(ob_list_handlers());
ob_end_flush();
?>
array(1) {
  [0]=>
  string(22) "default output handler"
}
array(1) {
  [0]=>
  string(22) "default output handler"
}
array(1) {
  [0]=>
  string(7) "print_r"
}
array(1) {
  [0]=>
  string(19) "userDefinedFunction"
}
array(1) {
  [0]=>
  string(17) "Closure::__invoke"
}
array(1) {
  [0]=>
  string(17) "Closure::__invoke"
}
array(1) {
  [0]=>
  string(17) "Closure::__invoke"
}
array(1) {
  [0]=>
  string(21) "MyClass::staticHandle"
}
array(1) {
  [0]=>
  string(15) "MyClass::handle"
}
array(1) {
  [0]=>
  string(17) "MyClass::__invoke"
}

ob_end_clean``ob_end_flush``ob_get_flush``ob_start