0

If I run php artisan tinker the CLI will open with

Psy Shell v0.8.6 (PHP 7.0.8 — cli) by Justin Hileman
>>>

Now I enter a word like 'test' and press the return key.

  • What mode did I enter?
  • How can I exit this mode? (ctrl+c exits tinker, but actually I only want to be able to execute commands again as usual which means I type in a command and when I press the return key it will be executed)
  • How can I execute commands in this mode. If I press enter in this mode I will move to the next line, but the command is not executed.
Andreas
  • 687
  • 2
  • 9
  • 20

3 Answers3

1

When I type run PsySH and then type test, I don't enter a different mode. I actually get an error that reads:

PHP Warning: Use of undefined constant test - assumed 'test' (this will throw an Error in a future version of PHP) in Psy Shell code on line 1

This might be a version issue.

But...

I think I know the mode you're talking about. You can enter that mode by typing one single quote ' and pressing Enter.

What PsySH is doing is letting you supply input across multiple lines. If, on the next line you just type '; you should see "\n" because it captured the Enter that you pressed.

If you want to exit this mode, you can either:

  • Close whatever opening statement you made. You can enter this mode by typing "function { + Enter", "for(;;) { + Enter", the single-quote, and many other things. You need to type the appropriate closing for the statement you started. For a function, }. For a string, ' or ", etc.
  • Press ^D (Control+D). This will put you back at the PsySH prompt. This will also work in many regular system shells, because ^D sends the End-Of-File character.
0
  • Tinker is a command line tool that lets you interact with Laravel from the command line.
  • You can exit tinker mode with either ctrl+c (as you mentioned) or typing exit; and hitting enter.
  • Tinker is based on PsySH, you can think of this mode as a line-by-line interactive PHP parser.

So, for example, you can do something like this:

$ php artisan tinker
Psy Shell v0.7.2 (PHP 5.6.30-7+deb.sury.org~trusty+1 — cli) by Justin Hileman
>>> $testString = "test";
=> "test"
>>> echo $testString;
test⏎
=> null
>>> exit;
Exit:  Goodbye.
Samsquanch
  • 8,866
  • 12
  • 50
  • 89
  • 1
    Thanks for the quick reply. The only thing that is not working on my side is that if I write exit; and press enter, the next message will not be Exit: Goodbye. Instead I will enter a new line. – Andreas Jun 27 '17 at 16:52
  • It could be version differences. I'm on PHP 5.6 and an older version of PsySH. I generally just use ctrl + c, personally. – Samsquanch Jun 27 '17 at 16:58
  • What happens when you type the word 'test' as the first action after you start tinker and press enter. As next you type echo "hallo"; and press enter. Does this work on your side? On my side echo "hallo"; is not executed when I press enter. I would expect to get hallo⏎ back, but when I press enter I will go to the next line. – Andreas Jun 28 '17 at 03:26
  • In the first case I get an error, in the second I get the expected text back. Have you tried updating? Your version may just not be working. – Samsquanch Jun 28 '17 at 14:39
0

while you are in tinker just type

exit;