问题与fgtecsv和无效的文件句柄

The following code echos "Null" but how is this possible? The fopen returns not false (i.e. a valid file handler) but the fgetcsv returns NULL which means invalid file handler given. I don't understand this.

if ($fh = fopen("2014_01.csv", 'r') !== FALSE) {
    if ($test = fgetcsv($fh, 0, ';') == NULL)
        echo "Null";
    fclose($fh);
} else
    echo "fh error";

Take a look at the PHP operators precedence. The comparison (==) has higher precedence than the assignment (=), that's why it evaluates like this:

if ($fh = (fopen() !== FALSE)) {
    if ($test = (fgetcsv() == NULL))

And this is not what you want. Put parenthesis around the assignments:

if (($fh = fopen("2014_01.csv", 'r')) !== FALSE) {
    if (($test = fgetcsv($fh, 0, ';')) == NULL)