/** * Invoke a Psy Shell from the current context. * * For example: * * foreach ($items as $item) { * \Psy\Shell::debug(get_defined_vars()); * } * * If you would like your shell interaction to affect the state of the * current context, you can extract() the values returned from this call: * * foreach ($items as $item) { * extract(\Psy\Shell::debug(get_defined_vars())); * var_dump($item); // will be whatever you set $item to in Psy Shell * } * * Optionally, supply an object as the `$bind` parameter. This determines * the value `$this` will have in the shell, and sets up class scope so that * private and protected members are accessible: * * class Foo { * function bar() { * \Psy\Shell::debug(get_defined_vars(), $this); * } * } * * This only really works in PHP 5.4+ and HHVM 3.5+, so upgrade already. * * @param array $vars Scope variables from the calling context (default: array()) * @param object $bind Bound object ($this) value for the shell * * @return array Scope variables from the debugger session. */ public static function debug(array $vars = array(), $bind = null) { echo PHP_EOL; if ($bind !== null) { $vars['this'] = $bind; } $sh = new \Psy\Shell(); $sh->setScopeVariables($vars); $sh->run(); return $sh->getScopeVariables(); }
/** * Invoke a Psy Shell from the current context. * * For example: * * foreach ($items as $item) { * \Psy\Shell::debug(get_defined_vars()); * } * * If you would like your shell interaction to affect the state of the * current context, you can extract() the values returned from this call: * * foreach ($items as $item) { * extract(\Psy\Shell::debug(get_defined_vars())); * var_dump($item); // will be whatever you set $item to in Psy Shell * } * * @param array $vars Scope variables from the calling context (default: array()) * * @return array Scope variables from the debugger session. */ public static function debug(array $vars = array()) { echo PHP_EOL; $sh = new \Psy\Shell(); $sh->setScopeVariables($vars); $sh->run(); return $sh->getScopeVariables(); }