-
Notifications
You must be signed in to change notification settings - Fork 115
Basic Usage
When Boris starts, you will be at the boris> prompt. PHP code you enter at
this prompt is evaluated. If an expression spans multiple lines, Boris will
collect the input and then evaluate the expression when it is complete. Press
CTRL-C to clear a multi-line input buffer if you make a mistake. The output
is dumped with var_dump() by default.
boris> $x = 1;
int(1)
boris> $y = 2;
int(2)
boris> "x + y = " . ($x + $y);
string(9) "x + y = 3"
boris> exit;
You can also use CTRL-D to exit the REPL.
Long-running operations, such as infinite loops, may be cancelled at any time without quitting the REPL, by using CTRL-C while the operation is running.
boris> for ($i = 0; ; ++$i) {
*> if ($i % 2 == 0) printf("Tick\n");
*> else printf("Tock\n");
*> sleep(1);
*> }
Tick
Tock
Tick
Tock
Tick
Tock
Tick
^CCancelling...
boris>
You can also use Boris as part of a larger project (e.g. with your application environment loaded).
require_once 'lib/autoload.php';
$boris = new \Boris\Boris('myapp> ');
$boris->start();
The constructor parameter is optional and changes the prompt.
If you want to pass local variables straight into Boris (e.g. parts of your application), you can do that too (thanks to @dhotston):
$boris = new \Boris\Boris('myapp> ');
$boris->setLocal(array('appContext' => $appContext));
$boris->start();
In the above example, $appContext will be present inside the REPL.