The same rules apply when dynamically referencing a variable. If $message is 'foo', referencing $$message will not implicitly define $foo and if $foo has not already been defined PHP will issue a notice. If you assign a value to $$message and $foo is not defined, $foo will be defined and the value assigned to it.
PHP Code:
$message = 'foo';
echo $$message; //this will issue a notice
$message = 'foo';
$$message = 'bar';
echo $foo; //this will output bar
echo $$message; //this will also output bar
This isn't the most commonly used language feature, but knowing it can save you some time occasionally. Today, actually, I happened to use it:
PHP Code:
$data = array('a' => null, 'b' => null, 'c' => null);
foreach($data as $var => $dontuse)
$$var = &$data[$var];
What this does is takes each item in the data array and defines a variable for each key in the array. The variable is actually a reference to the element in the array. The following code:
PHP Code:
$data = array('a' => null, 'b' => null, 'c' => null);
foreach($data as $var => $dontuse)
$$var = &$data[$var];
$a = 1;
$b = 2;
$c = 3;
print_r($data);
will output
Code:
Array
(
[a] => 1
[b] => 2
[c] => 3
)
Can you clarify what you're asking about sleep? All it does is halts the execution of a script for a certain amount of time (in seconds).
PHP Code:
$a = 5;
$b = 3;
sleep(3); //wait 3 seconds
echo $a + $b;
The total execution time of the above script will basically be 3 seconds since none of the operations (other than sleep) take any significant amount of time.