3 ms·
I wrote a PHP repl back in the 5.2 days as I wanted one that could auto-complete, use readline, and survive fatal errors. My solution (really an experiment) was
by apinstein 12y ago
I wrote a PHP repl back in the 5.2 days as I wanted one that could auto-complete, use readline, and survive fatal errors. My solution (really an experiment) was to write all the commands in a temp file and run that file out-of-band. This worked, but caused problems with having to pass global state around, and it didn't allow you to preserve local vars pointing to resources and such.
I dug into his code to see how he accomplished this:
* EvalWorker is responsible for evaluating PHP expressions in forked processes *
Which is a pretty cool setup. The whole thing is nicely architected and I'm looking forward to being able to use it!
- amasad 12y agoah interesting, so run the expression in the worker and check the return code? But what if that expression partially ran and had side effects?
- apinstein 12y agoexactly. side effects were definitely a problem, but it was an experiment and better than losing 20 prior commands! I looked at his source and it's not clear to me how he's also not having the same problem; if the statement is run in a fork then how do you propagate the newly created resources back up to the master? It's impressive though and works well.