I would like to execute a single php statement like if(function_exists(\"my_func\")) echo \'function exists\';
directly with the command line without having to
If you're using Laravel, you can use php artisan tinker
to get an amazing interactive shell to interact with your Laravel app. However, Tinker works with "Psysh" under the hood which is a popular PHP REPL and you can use it even if you're not using Laravel(bare PHP):
// Bare PHP:
>>> preg_match("/hell/", "hello");
=> 1
// Laravel Stuff:
>>> Str::slug("How to get the job done?!!?!", "_");
=> "how_to_get_the_job_done"
One great feature I really like about Psysh is that it provides a quick way for directly looking up the PHP docs from the command line. To get it to work, you only have to take the following simple steps:
apt install php-sqlite3
and then get the required PHP docs database and move it to the proper location:
wget http://psysh.org/manual/en/php_manual.sqlite
mkdir -p /usr/local/share/psysh/ && mv php_manual.sqlite /usr/local/share/psysh/
now for instance: