

Boris – A tiny REPL for PHP - tejasmanohar
https://github.com/d11wtq/boris

======
McGlockenshire
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.

~~~
zerocrates
PHP's built-in interactive mode isn't a REPL, there's no "P".

~~~
agumonkey
How a single missing letter can turn into a major inconvenience.

~~~
tejasmanohar
Indeed

~~~
shaftoe
It seems like the only thing needed to add the P is a var_dump.

Am I missing something here?

~~~
McGlockenshire
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.

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

------
gourneau
I have used [http://www.phpsh.org/](http://www.phpsh.org/) for years.

~~~
brokentone
While I also use it, phpsh is not a REPL, it's just an interactive shell, and
it doesn't have multiline support.

------
fishnchips
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?

~~~
tejasmanohar
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.

~~~
jeremyworboys
I would attribute a percentage of the downloads for Boris to being included in
Laravel 4.

Laravel 5 is now using PsySH.

~~~
bobthecow
Data point: PsySH went from ~15k Packagist downloads total to ~6-8k downloads
per day when Laravel 5 shipped.

~~~
tejasmanohar
Wait, a decrease... That's strange!

~~~
bobthecow
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_.

------
amasad
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](http://repl.it/languages/PHP)

~~~
apinstein
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
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?

~~~
apinstein
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.

------
collyw
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)?

~~~
keypusher
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.

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

~~~
bobthecow
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.

------
aikah
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?

~~~
McGlockenshire
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...

