Yahoo Phone Interview

1) Write a function to accept seconds and print time in format hh:mm:ss
2) If the same function is to be used multiple times how would we optimize the code so that we don’t have to calculate it each time. (hint: use static)

 
function formatTime($seconds) {
    if !($seconds) {
        return "";
    }
    static $timeArray = array();
    if (isset($timeArray[$seconds])) {
        echo "using cache\n";
        return $timeArray[$seconds];
    }
    $origSeconds = $seconds;
    $hours = floor($seconds / 3600);
    $seconds = $seconds % 3600;
    $mins = floor($seconds / 60);
    $seconds = $seconds % 60;
    $ret = sprintf("%02d::%02d::%02d", $hours, $mins, $seconds);
    $timeArray[$origSeconds] = $ret;
    return ($ret);
}

3) Can cookies be stolen ?
Yes cookies can be stolen. XSS is one way to do it.
https://www.go4expert.com/articles/stealing-cookie-xss-t17066/

4) Interface vs Abstract class
5) When does the page on screen get refreshed ?
Repainting and Reflowing
http://frontendbabel.info/articles/webpage-rendering-101/
http://www.phpied.com/rendering-repaint-reflowrelayout-restyle/
http://taligarsiel.com/Projects/howbrowserswork1.htm