Created
March 28, 2013 14:17
-
-
Save pavlepredic/5263451 to your computer and use it in GitHub Desktop.
Interactive PHP shell.
In Windows, running php in interactive mode is pretty quirky. This script attempts to solve this problem. It allows entering entire function definitions and classes. You may enter code on multiple lines. Nothing will be evaluated until you enter a semicolon. Save this to a file and run it from console. Hit CTRL+C to exit.
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 | |
$fh = fopen('php://stdin', 'r'); | |
$cmd = ''; | |
$bcLvl = 0; | |
while (true) | |
{ | |
$line = rtrim(fgets($fh)); | |
$bcLvl += substr_count($line, '{') - substr_count($line, '}'); | |
$cmd.= $line; | |
if ($bcLvl > 0 or substr($cmd, -1) !== ';') | |
continue; | |
eval($cmd); | |
$cmd = ''; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment