Skip to content

Instantly share code, notes, and snippets.

@andriidemus
Created May 25, 2013 04:55
Show Gist options
  • Select an option

  • Save andriidemus/5647956 to your computer and use it in GitHub Desktop.

Select an option

Save andriidemus/5647956 to your computer and use it in GitHub Desktop.
<?php
class Repl {
protected $promt = "hi";
protected function readLine() {
print($this->promt . '> ');
if (PHP_OS == 'WINNT') {
$line = stream_get_line(STDIN, 1024, PHP_EOL);
} else {
$line = readline();
}
return $line;
}
public function run() {
while (($line = $this->readLine()) !== 'exit') {
if (preg_match("/^\//", $line)) {
eval(substr($line, 1) . ";");
print(PHP_EOL);
} else {
eval("var_dump(" . $line . ");");
}
}
}
}
$repl = new Repl();
$repl->run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment