Skip to content

PHP RFC: __debugInfo() #1647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

PHP RFC: __debugInfo() #1647

wants to merge 2 commits into from

Conversation

Mhar14
Copy link

@Mhar14 Mhar14 commented Nov 21, 2015

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 __debugInfo().

Example Usage:

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

// But all the stream meta data is
public function __debugInfo() {
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...
*/

class Foo {
  private $val = 'Random, meaningless data';

  public function count() { return 42; }

  public function __debug_info() {
    return ['count' => $this->count()];
  }
}

$f = new Foo;
var_dump($f);
@nikic
Copy link
Member

nikic commented Nov 21, 2015

What's this PR about? The RFC has already landed a long time ago.

@laruence
Copy link
Member

close this as this RFC has been implemented.

@laruence laruence closed this Nov 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants