ID:               26411
 Comment by:       ois at oisnot dot com
 Reported By:      php at bellytime dot com
 Status:           Open
 Bug Type:         Feature/Change Request
 Operating System: *
 PHP Version:      *
 New Comment:

try {
  foreach ($nullValue as $nothing) {
    echo 'valid input';
  } else {
    //suppress notice
    echo 'null value';
  }
  //or/and
} catch (ExceptionObjectNotIterator $e) {
  //object doesnt implement Iterator
  echo $e->getMessage();
}


Previous Comments:
------------------------------------------------------------------------

[2003-11-29 08:59:16] [EMAIL PROTECTED]

Yes, you're right, my code was wrong. Next try:

$found = false;
while ($row = mysql_fetch_assoc($result)) {
   $found = true;
   print 'Here is a result';
   ...
} 

if (!$found) {
   print 'No results found';
}


The proposed while/else syntax is indeed a bit more elegant.


------------------------------------------------------------------------

[2003-11-26 17:21:53] [EMAIL PROTECTED]

Read again. Your code would always print 'No results found' while the
intended change wouldn't.

------------------------------------------------------------------------

[2003-11-25 19:16:51] [EMAIL PROTECTED]

Can you give a better example to support your request? Your example can
easily be written as:

while ($row = mysql_fetch_assoc($result)) {
   print 'Here is a result';
   ...
} 

if (!row) {
   print 'No results found';
}

I don't think that this one test is so expensive that it makes it worth
the trouble (and cost) to clutter up the language.

------------------------------------------------------------------------

[2003-11-25 12:28:30] php at bellytime dot com

Description:
------------
How about a while...else structure. Often we do 

if (!mysql_num_rows($result)) {
   print 'No results found';
}
while ($row = mysql_fetch_assoc($result)) {
   print 'Here is a result';
   ...
}

Wouldn't it be nicer to do a 

while ($row = mysql_fetch_assoc($result)) {
   print 'Here is a result';
   ...
} else {
   print 'No results found';
}




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=26411&edit=1

Reply via email to