A possible solution is to use proc_open
(Documentation) instead:
$pipes = array();
$editRes = proc_open(
"$editor $tmpfile",
array(
0 => STDIN,
1 => STDOUT,
2 => STDERR
),
$pipes
);
proc_close($editRes);
Error handling omitted for brevity.