In this quick-tip I’ll introduce you to a tool called phpsh. This project has been created for quite some time now. It was created at Facebook but is no longer actively being developed. But this shouldn’t stop you from using it. It’s a really important tool to have especially when you want to quickly test a PHP script. PHPsh is an interactive shell for PHP. It’s features include the following:
- readline history
- tab completion
- quick access to documentation
You can download it directly from this link.
Once you’re done downloading phpsh, extract the zip file and navigate to the extracted folder. Then execute the following commands to install it in your system.
Once that’s done, you can now open any terminal window and execute
phpsh to start using it.
To get documentation regarding a specific function, use the
d command followed by the name of the function you want to look up. Here are a few examples.
1 2 3
It will then output the documentation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
Aside from directly accessing the docs, you can also write and execute any PHP code that you wish to test. Here’s a screenshot of me declaring an array and then looping through it.
You can also connect to a database and perform operations on it.
That’s it for this quick-tip. I hope I’ve encouraged you to use phpsh on your projects.