It happen when i have a code like below

function connect()
{
    return sqlsrv_connect(..);
}
..

$result = sqlsrv_query(connect(), $sql);  

The error mysteriously went away when i change the code to this

$connect = connect();
$result  = sqlsrv_query($connect, $sql);