While using php artisan tinker
, I changed some class files in my project. Is there a way to reload the REPL without having to type exit
and php artisan tinker
again?
Asked
Active
Viewed 1,479 times
1 Answers
11
If the sequence CTRL+d, up, enter is too long for you, you could file a feature request with laravel, but last time I checked you couldn't Redefine Class Methods or Class , so I think isn't a trivial thing to do.
If tinkering is all you do you could make it even shorter starting your tinker session with
$ while true; do php artisan tinker; done
Now just the CTRL+d will reload the tinker session.
And if that is too much to type you could define a Terminal/iTerm Profile with this command:
/bin/sh -c 'while true; do php artisan tinker; done'

Community
- 1
- 1

Chris Wesseling
- 6,226
- 2
- 36
- 72
-
Oh yes, 4 key presses are too long! The loop is a good remedy. I was wondering if tinker (or boris) can reset itself. It should be fairly easy to implement. – Dave Apr 24 '14 at 22:56
-
@Dave has it become easy to redefine classes and functions in PHP? – Chris Wesseling Apr 24 '14 at 22:58
-
I think resetting the REPL just requires setting a hook in boris and starting a new \Boris\Boris instance. – Dave Apr 25 '14 at 02:53
-
`I changed some class files in my project` So then you or Boris will need to re-include them. And last I checked, *that* will result in [I'm sorry @Dave, I'm afraid I can't do that](http://stackoverflow.com/questions/708140/php-fatal-error-cannot-redeclare-class). PHP wasn't designed for long running processes, it [evolved](http://php.net/manual/en/history.php.php) from a CGI tool with a runtime with a lifespan of a HTTP request. What your Boris hook needs is a PHP equivalent for Pythons [reload](https://docs.python.org/2/library/functions.html#reload). If that exists, then it should be easy. – Chris Wesseling Apr 25 '14 at 07:10
-
I was thinking in terms of using PCNTL to do the reset (from TinkerCommand). But now that I think about it, it may not work exactly and if it does, it seems a bit hackish to implement. – Dave Apr 26 '14 at 06:13
-
Thanks for the super useful Trick :) – Vinay Aggarwal Jun 13 '15 at 03:03