Skip to content

Fuco1/ob-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

ob-php

Org mode Babel support for PHP

Prerequisites for Sessions

Per default Babel doesn’t use Sessions, so this is only needed for advanced operations…

  • boris - PHP Read Eval Print Loop (REPL)

    https://github.com/d11wtq/Boris

    I wasted many hours trying to get the lousy PHP shell to work here (php -a). Then I discovered that it wasn’t even the real shell, but “interactive mode”. I have no idea why as =readline= was available.

    I also had to comment this in php.ini for Boris to work:

    ; disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
        
  • php-boris - an Emacs extension for Boris

    From MELPA, install via M-x package-install

    Currently only sessions with output work

Manual installation

Load/evaluate the code and require ob-php

(with-temp-buffer
  (url-insert-file-contents "https://raw.github.com/steckerhalter/ob-php/master/ob-php.el")
  (eval-buffer))
(require 'ob-php)

Add PHP to the allowed languages for Babel

(add-to-list 'org-babel-load-languages '(php . t))
(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)

That’s it, you should be good to go!

El-Get Recipe

(:name ob-php
       :type http
       :url "https://raw.github.com/steckerhalter/ob-php/master/ob-php.el"
       :prepare (progn
                  (add-to-list 'org-babel-load-languages '(php . t))
                  (org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)))
))

Usage

No session

4 + 4;
print "dude\n";
print $x;
return $y;
4 + 4;
print "dude\n";
print $x;
return $y;

Pretty printing

$dude = new stdClass();
$dude->man = "green";
$dude->pleora = new stdClass();
return $dude;

Org output

$test = array(
    array('forest', 'green'),
    array('sea',  $sea),
);

foreach ($test as $row) {
    foreach($row as $cell) { print '|' . $cell; };
    print "\n";
}

Session with output

  • Note taken on [2013-08-06 Tue 01:43]
    This is wrong and should be fixed. The result is not really output!
$x = array("mond" => "schein", array("sonate", "betthofen"));

Use previouly defined PHP variable

print $x;

Why does this make an example block?

var_dump($x);

body { margin: 20px !important; }

Options