phpsh -- An interactive shell for php

phpsh is an interactive shell for php that features readline history, tab completion, quick access to documentation. It was developed at Facebook and ironically, is written mostly in python. It is open source and released under a modified BSD license.

If you don't have --with-readline and --with-libedit compiled into your PHP binary but you do have Python2.4 installed, you may find this useful. If your PHP binary includes the readline module, you may prefer one of the pure PHP alternatives you can find by searching the Internet.

The source code for phpsh is now available on github at http://github.com/facebook/phpsh.

If you use git, you can clone the source repository by doing:
git clone git://github.com/facebook/phpsh.git
You can also download a snapshot of the latest version as either a zip or gzipped tarball.

README | License | Contact | Twitter | Facebook Page | by Dan Corson and Charlie Cheever
ccheever@bamboo:~$ phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> h
-- Help --
Type php commands and they will be evaluted each time you hit enter. Ex:
php> $msg = "hello world"

Put = at the beginning of a line as syntactic sugar for return. Ex:
php> = 2 + 2
4

phpsh will print any returned value (in yellow) and also assign the last
returned value to the variable $_.  Anything printed to stdout shows up blue,
and anything sent to stderr shows up red.

You can enter multiline input, such as a multiline if statement.  phpsh will
accept further lines until you complete a full statement, or it will error if
your partial statement has no syntactic completion.  You may also use ^C to
cancel a partial statement.

You can use tab to autocomplete function names, global variable names,
constants, classes, and interfaces.  If you are using ctags, then you can hit
tab again after you've entered the name of a function, and it will show you
the signature for that function.  phpsh also supports all the normal
readline features, like ctrl-e, ctrl-a, and history (up, down arrows).

Note that stdout and stderr from the underlying php process are line-buffered;
so  php> for ($i = 0; $i < 3; $i++) {echo "."; sleep(1);}
will print the three dots all at once after three seconds.
(echo ".
" would print one a second.)

See phpsh -h for invocation options.

-- phpsh quick command list --
    h     Display this help text.
    r     Reload (e.g. after a code change).  args to r append to add
            includes, like: php> r ../lib/username.php
            (use absolute paths or relative paths from where you start phpsh)
    R     Like 'r', but change includes instead of appending.
    d     Get documentation for a function or other identifier.
             ex: php> d my_function
    D     Like 'd', but gives more extensive documentation for builtins.
    v     Open vim read-only where a function or other identifer is defined.
             ex: php> v some_function
    V     Open vim (not read-only) and reload (r) upon return to phpsh.
    e     Open emacs where a function or other identifer is defined.
             ex: php> e some_function
    x [=]function([args]) Execute function() with args under debugger
    c     Append new includes without restarting; display includes.
    C     Change includes without restarting; display includes.
    !     Execute a shell command.
             ex: php> ! pwd
    q     Quit (ctrl-D also quits)

php> = 3 + 3
6
php> = $_
6
php> $x = $_

php> print $x
6
php> = func
func_get_arg     func_num_args    function_exists  
func_get_args    function         
php> = function_exists
function_exists
php> = function_exists('function_exists')
true
php> d array_merge

# array_merge

(PHP 4, PHP 5)

array_merge -- Merge one or more arrays

### Description

array array_merge ( array $array1 [, array $array2 [, array $... ]] )

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array. 

If the input arrays have the same string keys, then the later value for that key will overwrite the previous one. If, however, the arrays contain numeric keys, the later value will not overwrite the original value, but will be appended. 

If only one array is given and the array is numerically indexed, the keys get reindexed in a continuous way. 

### Parameters

array1     

Initial array to merge. 

array     

Variable list of arrays to recursively merge. 

### Return Values

Returns the resulting array. 

###

php> = 2 +
 ... 2
4
php> = array(array(1,2,3), array("a" => "b", "c" => "d"), "e", "g")
array(
  0 => array(
    0 => 1,
    1 => 2,
    2 => 3,
  ),
  1 => array(
    "a" => "b",
    "c" => "d",
  ),
  2 => "e",
  3 => "g",
)
php> q