Maybe use the built-in PHP parser to see if we're in the middle of a statement and allow multi-line input until a ; or some other signal is entered on a single line?
Or maybe have a multi-line internal command? like
foreach ($a as $b) {
print $b;
}
;