Created
November 19, 2013 13:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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