User input in php command line

Ever wondered how to capture the user input when writing php command line scripts ?

<?php
 
function getInput($msg){
  
fwrite(STDOUT"$msg: ");
  
$varin trim(fgets(STDIN));
  return 
$varin;
}
 
?>

The function above is being used by me in certain command line scripts, where I need user responses.