Class it:

/**
 * Get one line from stdin (or files given on command line) a la Perl <>.
 * Note: You need to call getopt() before using this function.
 * @return Line (including newline) or false on eof
 */
static function gets()
{
    static $initialized = 0;

    if (!$initialized++)
        it::_stdin_next();

    do {
        $result = fgets($GLOBALS['it_stdin']['fd']);
    } while (($result === false) && it::_stdin_next());

    $GLOBALS['it_stdin']['line']++;
    return $result;
}