Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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