Skip to content

Instantly share code, notes, and snippets.

@adrienlucas
Created November 19, 2013 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrienlucas/7545468 to your computer and use it in GitHub Desktop.
Save adrienlucas/7545468 to your computer and use it in GitHub Desktop.
Dumb class that can be used to debug a third-party object calls.
<?php
class HackableObject {
protected $obj;
public function __construct($obj){
$this->obj = $obj;
}
public function __destruct(){
}
public function __call($f, $a){
if($f == 'flush') {
var_dump($this->obj->isOpen());
var_dump($this->__trace());
}
$r = call_user_func_array(array($this->obj, $f), $a);
if(!$this->obj->isOpen()) {
var_dump($this->__trace());
}
return $r;
}
protected function __trace() {
$t = debug_backtrace(false);
$s = array();
array_shift($t);
while(!empty($t)) {
$i = array_shift($t);
$s[] = (isset($i['file']) ? $i['file'] : '').':'.(isset($i['line']) ? $i['line'] : '');
}
return implode(' < ', $s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment