Skip to content

Instantly share code, notes, and snippets.

@jm42
Created October 22, 2014 18:46
Show Gist options
  • Save jm42/c895d757ebfc005e72dd to your computer and use it in GitHub Desktop.
Save jm42/c895d757ebfc005e72dd to your computer and use it in GitHub Desktop.
Using `$started || start()`;
<?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