17 févr. 2014

Meet Boris: PHP, too has its REPL

What? REPL? It stands for Read-Eval-Print-Loop. Basically, it is a form of a language interpreter that allows you to enter into a dedicated prompt, evals each commands that you pass in and prints out their results. Think of Bash, Zsh, SQlite, Redis, Coffee, NodeJS, iPython, ... You enter your commands, one at the time, and they prints out their results, one at the time. And then?

PHP on the CLI is only an interpreter. Thus, it is capable of evaluating commands and scripts. But, it can't let you pile up commands and spit out their results line by line. It has no REPL capabilities. And what?

REPL makes easy to check some aspect of a language. It lets you play with a language before coding your programs. Having this tool alongside prevents you from writing a ton of scriptlets just to check or enhance your development or improve your syntax.

Thankfully, here comes Boris. It is the REPL that PHP should have from its early days.

Installing it on OSX with Homebrew is easy as pie and is performed with these simple steps:
  1. Start by installing some new recipes (or formulas):
    brew tap josegonzalez/homebrew-php
  2. Then, install a local PHP interpreter. I prefer installing the 5.4 release as it matches the one provided with OSX but you can experiment with other if you plan on mimicking one of your servers in production:
    brew install php54

    Note: If you haven't done it before, Homebrew may warn you that a zlib dependencies is not met. In this case, follow his advice by running the following command and re-running the former one:
    brew tap homebrew/dupes
  3. Now, you should have a local PHP available. It is time to add a decent package management for it, Composer:
    brew install josegonzalez/php/composer
  4. And, now, let us invite Boris to the party:
    brew install boris
Use boris as any of your regular commands like any regular REPL in your Terminal or iTerm2 or whatever CLI you like.

Aucun commentaire:

Enregistrer un commentaire