apinstein / iphp Goto Github PK
View Code? Open in Web Editor NEWAn interactive php shell (REPL) with support for readline, autocomplete, include/require, and fatal-error tolerance.
An interactive php shell (REPL) with support for readline, autocomplete, include/require, and fatal-error tolerance.
this :
h:> php -f iphp.php
h:>
on windows 7;
how could i use the iphp.php?
See patch: http://github.com/jetviper21/iphp/commit/2ac55340d8c6654b703748b26ab585fc333fb66a#comment_38069
Read comments for architecture ideas.
Maybe use the built-in PHP parser to see if we're in the middle of a statement and allow multi-line input until a ; or some other signal is entered on a single line?
Or maybe have a multi-line internal command? like
foreach ($a as $b) {
print $b;
}
;
I have an idea to use token_get_all() to parse the input and do lexical analysis on the code entered so far to improve the autocomplete list.
So if you have a class Foo with methods bar() and baz() you would see:
$foo = new Foo;
$foo->b
bar baz
This could be done with real-time reflection.
@apinstein will you please give a status update
Where is the project at?
Where is the project going?
How much time can you commit to this project?
Known PHP version support?
Any other dependencies?
I installed and immediately readline is not working which is should so I haven't looked at it any closer thought I might get your response first.
I've been using facebook's phpsh and recently made some modifications realizing that there really isn't much preventing us from doing it all in php. Started playing with ipython and why don't we have iphp was the thought that came to mind. Hence a google search landed me here.
Interested? Plausible? Know of any other similar projects perhaps?
Looking forward to hearing your thoughts,.
the readme file should list the requirements for running iphp.
So far, I can see PHP 5 >= 5.1 is needed because of use of the readline_callback_handler_install function. and, php-cli is also needed.
also, PHP must be compiled with option --with-readline
A simple PEAR package for this project would make it really easy for php-ers to have a one-line install that will put the iphp bin in their path.
Eventually the (pearfarm project)[http://github.com/fgrehm/pearfarm] will help with that, but it's not quite ready yet...
Anyone wanna take a crack at the PEAR package?
I have readline installed, not sure why I am getting an undefined function call. System information and command output is below.
$ php -v PHP 5.2.11 (cli) (built: Nov 17 2009 19:18:54) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies with the ionCube PHP Loader v3.3.1, Copyright (c) 2002-2009, by ionCube Ltd., and with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
$ uname -a Linux eric-desktop.local 2.6.30.9-102.fc11.x86_64 #1 SMP Fri Dec 4 00:18:53 EST 2009 x86_64 x86_64 x86_64 GNU/Linux
$ ./iphp
Welcome to iphp, the interactive php shell!
Features include:
- autocomplete (tab key)
- readline support w/history
- automatically wired into your project's autoload
Enter a php statement at the prompt, and it will be evaluated. The variable $_ will contain the result.
Example:
> new ArrayObject(array(1,2))
ArrayObject Object
(
[0] => 1
[1] => 2
)
> $_[0] + 1
2
PHP Fatal error: Call to undefined function readline_callback_handler_install() in /home/eric/Source/iphp/iphp.php on line 191
PHP Stack trace:
PHP 1. {main}() /home/eric/Source/iphp/iphp:0
PHP 2. iphp::main($options = array ()) /home/eric/Source/iphp/iphp:7
PHP 3. iphp->readline() /home/eric/Source/iphp/iphp.php:276
PHP 4. iphp->myReadline() /home/eric/Source/iphp/iphp.php:209
Fatal error: Call to undefined function readline_callback_handler_install() in /home/eric/Source/iphp/iphp.php on line 191
Call Stack:
0.0006 94752 1. {main}() /home/eric/Source/iphp/iphp:0
0.0031 203216 2. iphp::main(array ()) /home/eric/Source/iphp/iphp:7
0.0291 755904 3. iphp->readline() /home/eric/Source/iphp/iphp.php:276
0.0291 755904 4. iphp->myReadline() /home/eric/Source/iphp/iphp.php:209
Presently a command like:
foreach(array(1,2) as $i) { echo $i; }
fails since the generated code is like:
$_ = foreach() ...
Maybe use the built-in php parser to figure out if we're in such a case?
This was bugging me for awhile and i hacked away for about 2.5 hours trying to figure out a work about but
example:
> $foo = function() {return 'bar';} > Uncaught exception with command: Fatal error executing php: PHP Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:18 Stack trace: #0 /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo(18): serialize(Array) #1 {main} thrown in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo on line 18 Exception: Serialization of 'Closure' is not allowed in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo on line 18 Call Stack: 0.0004 635040 1. {main}() /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:0 0.0009 637576 2. serialize() /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.U3N9Oo:18
Same goes for defining functions and classes
function:
> function foo() {return 'bar';} > Uncaught exception with command: Fatal error executing php: PHP Parse error: syntax error, unexpected T_STRING, expecting '(' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.8CUHcL on line 12 Parse error: syntax error, unexpected T_STRING, expecting '(' in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.8CUHcL on line 12 >
Classes:
> class Foo {} > Uncaught exception with command: Fatal error executing php: PHP Parse error: syntax error, unexpected T_CLASS in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.Pk4qgL on line 12 Parse error: syntax error, unexpected T_CLASS in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.Pk4qgL on line 12 >
While i had a work around working the storing of $_ and $__out are not possible when you create a a special case even "foreach" will explode using serialization
foreach(range(0,10) as $i) { echo $i; } > Uncaught exception with command: Fatal error executing php: PHP Parse error: syntax error, unexpected T_FOREACH in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.mXsYfJ on line 12 Parse error: syntax error, unexpected T_FOREACH in /private/var/folders/oQ/oQhij0hDFVOxzm9dMI9EC++++TI/-Tmp-/iphp.command.mXsYfJ on line 12 >
Solution is avoid serialization and store the code input unserialized in a file and keep appending to it and re-executing, As for returning output some string parsing may be in order to find variables and var_dump-ing them may be in order or just rely or just print tokenize the last returnable line;
edit: fixed typo's my brain is fried
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.