ZF-7288: Zend_Session::start overwrites error handler to test if session start failed

Description

I think it is better to check this by using error_get_last (http://de.php.net/manual/en/…) and since PHP 5.3 you can simply check the return value of session_start.

This could be the new session_start check


if (version_compare(PHP_VERSION, '5.3.0', '<')) {
    $errBefore = error_get_last();
    @session_start();
    $errAfter = error_get_last();
    if ($errBefore != $errAfter) {
        throw new Zend_Session_Exception('Failed to start session: ' . $errAfter['message']);
    }
} else {
    if (@session_start() === false) {
        $errLast = error_get_last();
        throw new Zend_Session_Exception('Failed to start session: ' . $errLast['message']);
    }
}

Comments

ZF-7288 would fix ZF-7217, too

As much as I can see from the PHP docs, there is no need for error suppression in the else block.

session_start() returns either true or false in PHP 5.3

I guess this is not the only thing that should change with 5.3 becoming more and more popular. I think there should be a single place where we could document issues like this one, so once the 5.3 becomes a requirement for running ZF we can get rid of the BC code.

But it restores the error handler right after:


if (self::$_throwStartupExceptions) {
    require_once 'Zend/Session/Exception.php';
    set_error_handler(array('Zend_Session_Exception', 'handleSessionStartError'), $errorLevel);
}

$startedCleanly = session_start();

if (self::$_throwStartupExceptions) {
    restore_error_handler();
}

So I don't see what the issue is. Could someone provide an example of why this behavior is bad/wrong?