-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Way to purge or reload modified code without exiting? #416
Comments
Unfortunately this isn't really possible. If you're still using 5.x there is a PHP extension called "runkit" which allows this. And PsySH even has support for that! But runkit doesn't support PHP 7, and the closest available option doesn't really support what we'd need for code reloading :( |
Wow thanks for the tip on runkit. After Googling, looks like there are some other PHP7 options: Soft-Mocks and UPOZ. |
Unfortunately neither of those allows re-importing files like runkit did. |
Ideally—and with the runkit code reloader this is possible—any existing objects you have would be redefined whenever you update their code. Something like Soft Mocks works by importing a different version every time you import code, but even if we got it working correctly, it would never update existing objects to match the new code. So if you create an object, then change its source code, then create an identical object, they won't have the same type. In my opinion, this is a worse place (read: less predictable and less understandable) to be in than having to reload your shell to pick up code changes. We'd also have to deal with all the gymnastics of mapping "user typed While it doesn't come with a built-in ability to re-import files, UOPZ has at least some of the functionality necessary to do code reloading: If we wrote a fairly sophisticated code reloader, we could delete and redefine methods on existing classes, and change them from private to public or vice versa. We could change the inheritance or interfaces of an already defined class. We could replace functions. And we could redefine constants. All of this would work with objects already instantiated in the shell. And this might be enough. I've definitely considered exploring it. If you want to take a shot, I'd welcome a pull request :) |
Man, thanks for the exquisite explanation of all this. Ultimately I realize that my ideal solution is to write a test and have a watcher replay the test as I make changes to the source. But using psysh is so much easier and immediate for prototyping or trying out ideas; it has a kind of "hands-on" feel and is always at the ready without additional setup. I wonder if it would be possible to use a simple record-reset-replay strategy.
|
Replaying input might work, but not for anything that's stateful. Database access, filesystem access, etc all break. |
What if there was a psysh command to just reload psysh with the same parameters it was originally started with? For example, if I ran:
And later typed:
It would be great if it could exit and reload the same entry scripts. Admittedly, this is not really much different from just exiting back to command prompt, hitting up arrow and enter to replay the last command, but it would save a few keystrokes. |
I agree with @SimonEast. This seems like something very easy to implement and would be much appreciated, especially now that we have |
All I want is to not have to |
I just added a section about this to the Troubleshooting wiki page. |
Hey there's an existing fork of runkit for php7. Unfortunatly the
Voilà |
Hey, first.. huge fan of psysh. Thanks for making such a fantastic tool.
My request may already be possible, or may be _im_possible to achieve with PHP. Ultimately it would be really awesome if I could:
Obviously there may need to be a "step 5a." in there where we "purge" the bytecode cache or something. Maybe it's not even possible to do this.
The text was updated successfully, but these errors were encountered: