Powered by Cellfex RSS Follow me on Spotify
3 Jun 2010

Assignment in condition in Zend Studio

Author: Edgars | Filed under: DailyStuff

Zend Studio is strict, much much more stricter towards syntax than PHP itself.

I finally came to this point where i find not normal regular
while($row=mysql_fetch_array)) {/* ... */} because Zend Studio also finds it not normal.
To make such statement “valid” not only for Zend Studio, but also for common sense, use this instead:
while(($row=mysql_fetch_array)) !== false) {/* ... */}

Another example comes out of PHP itself in  a page about readdir. Ironically it is also not valid according to Zend Studio, because there is assignment in condition.

So. In order to make PHP’s code valid, instead of:

<?php
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
?>
use
<?php
if (($handle = opendir('.'))!==false) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($handle);
}
?>

Tags: , , , ,

Leave a Reply