Issue with fgtecsv and invalid filehandle

Rafael Wörner

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";
axiac

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)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

NBuilder and DbContext invalid cast issue

分類Dev

New Apple ID Sign In invalid grant issue

分類Dev

New Apple ID Sign In invalid grant issue

分類Dev

@XmlElementRef issue: Invalid XmlElementRef on property {property}, Referenced element not declared

分類Dev

Xml parsing issue: not well-formed (invalid token)

分類Dev

Syntax error using a filehandle stored in a hash value

分類Dev

fgtecsvと無効なファイルハンドルの問題

分類Dev

python3 renderPM(?)filehandle pb(biopython経由)

分類Dev

php validation issue End of line character is invalid; expected "\n" but found "\r\n"

分類Dev

aem-6-2-replication-issue-for-node-taining-invalid-jcr-names

分類Dev

Swift3.0のFileHandleとJavaのFileInputStreamの違い

分類Dev

ファイル全体をメモリにロードするFilehandleクラス

分類Dev

mooseでデフォルトのFileHandle属性を設定するにはどうすればよいですか

分類Dev

Filehandleを開こうとすると、なぜ「ordie」が発生するのですか?

分類Dev

Issue with AppCompat

分類Dev

Shortcode issue

分類Dev

Issue with JsonConverter

分類Dev

Issue with .on('error')

分類Dev

Assembly issue with '['

分類Dev

setOnTouchListener issue

分類Dev

Issue with $_SESSION

分類Dev

Issue with .equals()

分類Dev

Scala REPL issue - Multiexpression issue

分類Dev

"Invalid constraint: the type used for the constraint is sealed" is invalid

分類Dev

Webpack : Invalid configuration object/ Invalid Module Entry

分類Dev

ajax invalid json, Why is this invalid JSON?

分類Dev

Why is *a{...} invalid indirect?

分類Dev

Why is *a{...} invalid indirect?

分類Dev

realloc() invalid old size

Related 関連記事

ホットタグ

アーカイブ