I would like to propose a change in how mysqli_fetch() signifies "no
more data." It should return NULL instead of MYSQLI_NO_DATA (a
positive value) because it leads to cleaner PHP code and is more
consistent with other MySQL fetch functions.

Currently, mysqli_fetch() returns one of three different values:

Value          | Meaning
---------------------------------
true           | Successful Fetch
false          | Error
MYSQLI_NO_DATA | No more data
---------------------------------

Returning the constant MYSQLI_NO_DATA (100) mimics the underlying
MySQL C API, but it leads to non-natural PHP Code:

while (MYSQLI_NO_DATA !== mysqli_fetch($db)) {
    // do something.
}

Every other MySQL function allows you to do:

while ($row = mysqli_fetch_row($db)) {
    // do something.
}

And I think it'd be much nicer to allow people to write:

while (mysqli_fetch($db)) {
    // do something.
}

Therefore, I propose that instead of returning MYSQLI_NO_DATA, we
return NULL. Here's my reasoning:

1) The other mysqli_fetch_* functions now return NULL in this
   situation.
2) We're already modifying the MySQL C-level return values. In C,
   mysql_fetch() returns 0 on success and 1 upon an error. We've
   swapped these values to behave more PHP-like.
3) When 0 signifies success, a positive "no more data" error code
   makes sense because it looks (logically) like an error inside a
   while. That doesn't hold true now that we've flipped these values.

-adam

-- 
[EMAIL PROTECTED]
author of o'reilly's php cookbook
avoid the holiday rush, buy your copy today!

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to