Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REPL/interactive shell with proper PHP 5.3 support?

I've been using phpsh for a while now, and it's worked great in the past. But its namespace support still isn't very good and this can be pretty frustrating.

Things like \Somespace\Someclass::someStaticFunction() don't work without disabling the check whether or not a method exists, which leads to frequent fatal errors on typos that reset your environment.

There are multiple PHP REPLs out there, including the PHP built-in shell (php -a), which is horrible to use.

Does anyone know of an alternative or perhaps a phpsh-fork with proper namespace support? Or perhaps an easy configuration fix I've overlooked...


an example:

This testfile:

<?
namespace testing;

function echoSome(){
        echo 'Something';
}

\testing\echoSome();

produces this output in phpsh (as expected)

php> include '/path/test.php';
Something
php>

But trying the same call again does not work:

php> \testing\echoSome();
Not executing input: Possible call to undefined function echoSome()
See /etc/phpsh/config.sample to disable UndefinedFunctionCheck.

without namespaces the function is still available:

<?
function echoSome(){
        echo 'Something';
}

echoSome();

in phpsh:

php> include '/path/test.php';
Something

and the call still works:

php> echoSome();
Something
like image 709
Marlies Avatar asked Jul 03 '12 10:07

Marlies


1 Answers

I found that using eval worked as a good workaround:

php> = eval('return \testing\echoSome();')

Yea, it's a hack but a handy one. :)

like image 83
Eric Anderson Avatar answered Nov 15 '22 18:11

Eric Anderson