30 comments

[ 3.6 ms ] story [ 70.0 ms ] thread
How does it differ from HHVM REPL or PsySH? I'm not a PHP dev so I may be missing some finer points of this project - care to elaborate?
I'll compare it to PsySH. Though this doesn't indicate any superiority in quality, I think it's important to note that Boris is arguably much more popular (measured in downloads from Packagist + stars on GitHub). From the start (back in 2011, before PsySH), Boris was meant to be tiny and light-weight in its core, weighing in at a few hundred lines of fairly straightforward code (brainstorming ideas for an extension API). Vanilla Boris is not as advanced as PsySH out-of-the-box, mostly a taste thing.
I would attribute a percentage of the downloads for Boris to being included in Laravel 4.

Laravel 5 is now using PsySH.

Data point: PsySH went from ~15k Packagist downloads total to ~6-8k downloads per day when Laravel 5 shipped.
Wait, a decrease... That's strange!
Sorry, my sentence was a bit ambiguous. Before Laravel 5 shipped, there had only been 15k Packagist installs total. After Laravel 5, it increased to almost half that every day.
Yeah, Boris downloads did spike quite a bit when Laravel 4 included it.
PsySH has a tendency to crash on fatal errors. If Boris figured out how to recover gracefully that would be a huge point in its favor.
Are you running Windows? If not, you've found a bug and should report it. If you are, you've discovered the reason Boris doesn't run at all on Windows :)

Seriously, though, if you're running on Windows you should report fatal errors that make PsySH crash as well. It works around a lot of them, but there will always be more, so let us know.

What advantage does this have over the built in REPL you can find with php -a (assuming readline instead of libedit)? They fixed fatal behavior a few versions ago, which was my last gripe with it.
PHP's built-in interactive mode isn't a REPL, there's no "P".
How a single missing letter can turn into a major inconvenience.
Indeed
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.
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!
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.

Still doesn't work on Windows. I don't care what people say ruby,node and python ,even Ipython repls work on Windows. So why can't we have a proper repl for PHP?
I don't know about the others, but this one works by using ext/pcntl, which isn't available natively on Windows. Try under cygwin? Crappy workaround...
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.
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.
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.