Live data from Hacker News

Boris – A tiny REPL for PHP

github.com

21–30 of 31 posts

Re: Boris – A tiny REPL for PHP

#21
post #9

I have a PHP REPL on repl.it [1] but it's admittedly not that great because certain errors are impossible to recover from, for example a call to an undefined function just kills the process. I don't know how Boris does it but I should just use it. [1]: http://repl.it/languages/PHP

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!

Re: Boris – A tiny REPL for PHP

#22
post #9

I have a PHP REPL on repl.it [1] but it's admittedly not that great because certain errors are impossible to recover from, for example a call to an undefined function just kills the process. I don't know how Boris does it but I should just use it. [1]: http://repl.it/languages/PHP

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…

ah interesting, so run the expression in the worker and check the return code? But what if that expression partially ran and had side effects?

Re: Boris – A tiny REPL for PHP

#23
post #15

Earlier quoted context omitted.

It seems like the only thing needed to add the P is a var_dump. Am I missing something here?

No, you aren't missing anything. Maybe it's the Stockholm Syndrome of using PHP every day speaking, but I'm personally quite satisfied actually having to ask for output.

Maybe you just know PHP in and out so much you don't even need output. Like people using ed.

Re: Boris – A tiny REPL for PHP

#26
post #22

Earlier quoted context omitted.

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…

ah interesting, so run the expression in the worker and check the return code? But what if that expression partially ran and had side effects?

exactly. 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.

Re: Boris – A tiny REPL for PHP

#27
post #25

REPL's seem to get a lot of love these days. Do they have any advantage over a step through debugger (other than startup time)?

I find the primary advantage of a REPL being able to "explore" the language, or code. If I am trying to figure out how to slice a particular list of items and then split the items on a regex into key-value pairs for a map, sometimes I just prefer instant feedback and being able to mess around with live variables. That being said I often find that after about 5 minutes in (Python's) REPL I start wishing I had just written a script and run it in the interpreter instead, as going back to edit functions or build classes can be painful. Stuff like iPython offer solutions to this problem by integration with editors and more.

Re: Boris – A tiny REPL for PHP

#29
post #25

REPL's seem to get a lot of love these days. Do they have any advantage over a step through debugger (other than startup time)?

The speed you get feedback is the key imo. When I use a language that has a repl I usually find myself using it more than the text editor / ide. And in my experience there's a nice side effect too: since you cannot write too much in the repl, you end up writing smaller functions that leads to more modular, reusable code.

Re: Boris – A tiny REPL for PHP

#30

I tried boris and psysh at work but they both failed when i wanted to redefine a function or a class.

Yeah. Unfortunately that's a limitation of PHP. It should be possible to use something like the Runkit extension to allow function and class redefinition, but it's not the best experience, and it requires compiling and installing a PHP extension that doesn't ship by default with any pre-built PHP I know of.
Post reply on HN