Skip to content

Instantly share code, notes, and snippets.

@rodrigosetti
Last active November 23, 2020 21:54
Show Gist options
  • Save rodrigosetti/35c124765f48323fc9a4 to your computer and use it in GitHub Desktop.
Save rodrigosetti/35c124765f48323fc9a4 to your computer and use it in GitHub Desktop.
Reasons I love PHP interactive shell

Reasons I love the PHP interactive shell

It won't display result of the evaluation. You have to output yourself

php > $x = "foo";
php > $x
php > ;
php > 
php > echo $x;
foo
php >

Fatal errors kills the shell

If you do something stupid (as we all do, that's why we need an interactive shell for experimenting), it kills the program at drop you back in the terminal. You loose all your work and have to start over.

Calling an inexistent function is a fatal

php > foo();
PHP Fatal error:  Call to undefined function foo() in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0

Redeclaring a function is a fatal

php > function f() {};
php > function f() {};
PHP Fatal error:  Cannot redeclare f() (previously declared in php shell code:1) in php shell code on line 1

Error messages are always in line 1

php > echo "hello world";
hello world
php > echo $x;
PHP Notice:  Undefined variable: x in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
php > echo $x;
PHP Notice:  Undefined variable: x in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
php > echo $x;
PHP Notice:  Undefined variable: x in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0

It's unforgetful when you forget a ";"

php > echo "hello world"
php > 
php > 
php > 
php > 
php > 
php > 
php > echo "what is going on?"
php > 
php > 
php > ;
PHP Parse error:  syntax error, unexpected T_ECHO, expecting ',' or ';' in php shell code on line 8
php >
@mikeschinkel
Copy link

"Fatal errors kills the shell"

And this makes you love it?

@EugeneDae
Copy link

LMAO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment