Apparently $pid is out of scope here. Shouldn\'t it be \"closed\" in with the function? I\'m fairly sure that is how closures work in javascript for example.
Accordi
I think PHP is very consistent in scoping of variables. The rule is, if a variable is defined outside a function, you must specify it explicitly. For lexical scope 'use' is used, for globals 'global' is used.
For example, you can't also use a global variable directly:
$n = 5;
function f()
{
echo $n; // Undefined variable
}
You must use the global keyword:
$n = 5;
function f()
{
global $n;
echo $n;
}