zrzut-ekranu-2016-09-27-o-18-57-35
If you know Python you know, that it has an interactive shell. The same as javascript, perhaps ruby and many many other languages. But did you know, that PHP has it also?

php -a

`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.
zrzut-ekranu-2016-09-27-o-19-07-08

php -r

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`.
zrzut-ekranu-2016-09-27-o-19-04-22

Summary

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!