Skip to content

Instantly share code, notes, and snippets.

@artembeloglazov
Created July 8, 2015 08:44
Show Gist options
  • Select an option

  • Save artembeloglazov/967d56d6eb4253b980f0 to your computer and use it in GitHub Desktop.

Select an option

Save artembeloglazov/967d56d6eb4253b980f0 to your computer and use it in GitHub Desktop.
Просмотр текущего стека и поиск нужных данных в вызываемых строках исходных кодов
public function __set($name, $value) {
try {
$setterGetter = $this->setterGetter($name, 'set');
} catch (\Exception $e){
if($e->getCode() == 3000){
$stack = debug_backtrace();
if(isset($stack[0]['file'])){
$fileName = $stack[0]['file'];
if(!array_key_exists($fileName, self::$fileCache)){
self::$fileCache[$fileName] = file($fileName);
}
$line = self::$fileCache[$fileName][$stack[0]['line'] - 1];
preg_match("/([a-zA-Z]*)->$name/", $line, $m);
if(isset($m[1]) && ($m[1] == 'this')){
goto set;
}
}
}
throw new \Exception($e->getMessage(), $e->getCode());
}
$value = $this->$setterGetter($value, $name);
set:
$this->$name = $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment