note 17868 modified in function.fopen by goba

From: Date: Tue, 01 Jan 2002 14:34:27 +0000
Subject: note 17868 modified in function.fopen by goba
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-24032@lists.php.net to get a copy of this message
Attn Perl Programmers: If you are used to writing script like do something || die("no can do"); note that in php || has a higher precedence than = So, don't write: $h = fopen("$filename", "r") || die("cannot open $filename"); b/c this will overwrite the file ptr! Now, or has a lower precedence than || and is also lower than = So, you may write: $h = fopen("$filename","r") or die("cannot open $filename"); However, you may avoid the entire issue with code like this: $h = fopen("$filename","r"); if (!$h) { die("unable to open $filename"); } --was-- Attn Perl Programmers: If you are used to writing script like do something || die("no can do"); note that in php || has a higher precedence than = So, don't write: $h = fopen("$filename", "r") || die("cannot open $filename"); b/c this will overwrite the file ptr! Now, or has a lower precedence than || and is also lower than = So, you may write: $h = fopen("$filename","r") or die("cannot open $filename"); However, you may avoid the entire issue with code like this: $h = fopen("$filename","r"); if (!$h) { die("unable to open $filename"); } http://www.php.net/manual/en/function.fopen.php

« previous php.notes (#24032) next »