Search code examples
phpshellread-eval-print-loopphpsh

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

Solution

  • There are a couple of alternatives.

    First of all, you might want to try the CLI for PHP 5.4. The interactive console has been greatly improved for 5.4, allegedly. They probably agreed with you that they built-in shell was horrible to use :) All I know is that it has been "refurbished".

    There are a few alternatives, such as phpa, which seems quite outdated, and running the latest git version of phpsh. They are aware of namespace issues, judging from their "Issues" page, so they might try to improve that. Since it's open source, you could get someone to fix it for you, or fix it yourself ;-)

    I think, overall you are faced with the choice between either the normal PHP CLI, or phpsh. There are no alternatives that are mature enough to do what either can do, and most alternatives are even more outdated (i.e., there is php_repl, which has been updated 3 years ago, as opposed to phpsh's 2 years).

    Good luck