13
votes

I'm getting started with a Laravel 5 project and trying to run some experiments using 'php artisan tinker' (psy shell), but I'm running into some weirdness. In the tinker/psy shell, pressing any of the arrow keys is printing character literals to the screen rather than performing the intended behaviour (move character for left and right, cycle recent commands for up and down).

Up is outputting ^[[A. Down is outputting ^[[B. Right is outputting ^[[C. Left is outputting ^[[D.

This is probably an issue with my terminal and not a Laravel bug. I am getting the same buggy behaviour when running php -a.

I am running terminal on OSX, with an xterm emulation.

4

4 Answers

34
votes

The PHP REPL does not implement readline's line editing and history capabilities. I don't know if there's a PHP module that implements it, but you can do:

rlwrap php artisan tinker

You may have to install rlwrap for your OS.

5
votes

This is due to PHP not being built with readline support. You can enable this when you compile and build PHP with the --with-readline argument.

http://php.net/manual/en/features.commandline.interactive.php

1
votes

MY os: centos I solved the problem by :

sudo yum install rlwrap
alias tinker='rlwrap php artisan tinker'

0
votes

In my case, I need install php7-readline

sudo zypper in php7-readline                                                       
[sudo] password for root: 
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following NEW package is going to be installed:
  php7-readline

1 new package to install.
Overall download size: 64.0 KiB. Already cached: 0 B. After the operation, additional 30.9 KiB will be used.
Continue? [y/n/...? shows all options] (y): 
Retrieving package php7-readline-7.2.1-1.1.x86_64                                                                 (1/1),  64.0 KiB ( 30.9 KiB unpacked)
Retrieving: php7-readline-7.2.1-1.1.x86_64.rpm ......................................................................................[done (8.4 KiB/s)]
Checking for file conflicts: ....................................................................................................................[done]
(1/1) Installing: php7-readline-7.2.1-1.1.x86_64 ................................................................................................[done]