Created
October 22, 2014 18:46
-
-
Save jm42/c895d757ebfc005e72dd to your computer and use it in GitHub Desktop.
Using `$started || start()`;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $started = false; | |
| function start() { | |
| global $started; | |
| if ($started) { | |
| print("Already started\n"); | |
| return; | |
| } | |
| print("Starting\n"); | |
| $started = true; | |
| } | |
| function run() { | |
| global $started; | |
| print("Running (is " . ($started ? 1 : 0) . ")\n"); | |
| $started || start(); | |
| print("Now is " . ($started ? 1 : 0) . "\n"); | |
| } | |
| run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment