`php -a` command opens interactive shell in which you can write some simple samples of code and quickly validate some of your ideas. It works like Python shell and you can write in it simple statements, functions and so on.
I’m using it every time I don’t want to create temporary files but quick validate my idea or check something.
PHP has another awesome command: `php -r`. It runs script placed within quotes. As simple as that. But it is extremely useful!
When I write tests in which I need unique identifiers I use timestamps. And the simplest way to get it is this simple script:
`php -r “echo time() . PHP_EOL;”`
As you can see it prints current timestamp and adds the newline (`PHP_EOL` is special PHP constant containing new line character specific for used operating systems). I’ve added it to my `.profile` file aliased as `uid` and every time I need new timestamp I just call `uid` in the terminal.
You can use it to create simple tools for yourself to simplify development. You can validate scripts even faster than using `php -a`.
This post is very short and tools described in it are very simple. But with a simple tool you can achieve great results if you use it properly. I can remember when I used a special temporary directory with temporary files just for validating simple scripts. Knowing `php -a` and `php -r` commands saved me a lot of time.
It can save yours too. Really.
Maybe you have some clever samples of using `php -r` command? Please, share them in comments 🙂
Don’t forget to check out other PHPhyts!
- PHPyths Buster: A great string performance test! (updated)
- PHPyths Buster: Single quotes are faster than double quotes
- PHPyths Buster: Annotations
- PHPyths Buster: End of the project
- PHPyths Buster: Displaying reminders
- PHPyths Buster: Evernote SDK [update]
- PHPyths Buster: Basic application
- PHPyths Buster: Hello World!
- PHPyths Buster: Project environment
- PHPyths Buster: The Project