Skip to content

Instantly share code, notes, and snippets.

@uzulla
Created April 14, 2014 16:49
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 uzulla/10664661 to your computer and use it in GitHub Desktop.
Save uzulla/10664661 to your computer and use it in GitHub Desktop.
Psysh をなんかこうグローバルで良い感じに…うーん、良い感じの書き方がおもいつかないでござる。
<?php
// config
define("DEBUG", true);
// loading
if(DEBUG)
include('/path/to/psysh');
// setup
set_error_handler(function($errno, $errstr, $errfile, $errline){
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
});
// use
try{
echo "Okay, I'll try read the file!";
$filename = "not exists file name here.";
file_get_contents($filename);
}catch(\Exception $e){
if(class_exists("Psy\\Shell")){\Psy\Shell::debug(get_defined_vars());}
}
$ php index.php
Okay, I'll try read the file!
Psy Shell v0.1.8 (PHP 5.5.9 — cli) by Justin Hileman
>>> ls
Variables: $_COOKIE, $_ENV, $_FILES, $_GET, $_POST, $_REQUEST, $_SERVER, $argc, $argv, $e, $filename
>>> ls $e
Class Properties: $xdebug_message
Class Methods: __construct, __toString, getCode, getFile, getLine, getMessage, getPrevious, getSeverity, getTrace, getTraceAsString
>>> $e->getMessage()
ErrorException with message 'Undefined variable: undefinedVariable'
>>> $e->getFile();
=> "/tmp/PsyshTest/index.php"
>>> $e->getLine();
=> 18
>>> echo $filename
not exists file name here.⏎
=> null
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment