rfc:debug-info

This is an old revision of the document!


PHP RFC: __debug_info()

Proposal

This RFC is for exposing the “get_debug_info” API already available to internal classes (written in C) to PHP classes via a magic method called __debug_info().

Example Usage:

class File {
  // "Resource(stream)" isn't all that useful
  private $fp;

  // But all the stream meta data is
  public function __debug_info() {
    return $this->fp ? stream_get_meta_data($fp) : [];
  }

  public function open($filename, $mode = 'r'){
    $this->fp = fopen($filename, $mode);
  }  
}

$f = new File;
var_dump($f); // object(File)#1 { }
$f->open('http://php.net');
var_dump($f);
/*
object(File)#1 {
  ["wrapper_type"]=>
  string(4) "http"
  ["stream_type"]=>
  string(10) "tcp_socket"
  etc...
*/

Backward Incompatible Changes

Double underscore is a reserved namespace, so any classes which happen to implement this are the ones which need to change.

Impact to Existing Extensions

Existing fallback behavior for internal classes not overriding get_debug_info is preserved via chaining to get_properties when no __debug_info function is defined.

Proposed PHP Version(s)

5.next

Implementation

rfc/debug-info.1390339570.txt.gz · Last modified: 2017/09/22 13:28 (external edit)