After the message from Philip Olson i was reminded that i had a little
discussion about return values but could not find everything i collected.

Some function return NULL some return FALSE and some return
either FALSE or NULL in case of an error.

I allways used to check for
xxx() !== false
since that is used in the documentation in some examples. See strpos().

Some function use NULL to tell there was a parser error and FALSE for
other errors. If so one cannot do something like:
if (xxx() !== false) ...
or
if (!is_null(xxx())) ...
instead you would have to use
if (($res = xxx() !== false) && !is_null($res)) ...

I posted the full thing already here. That also contains an analysis of
some function documentations:
http://marc.theaimsgroup.com/?l=php-dev&m=103376370906751&w=2

marcus

p.s.: I am crossposting this so that it might get attetion.

At 12:28 06.11.2002, Philip Olson wrote:


On Wed, 6 Nov 2002, Marcus Boerger wrote:
> It return false on failure as documented. I feel we should use this for all
> functions where any failure results in false. This way users easily know
> that they must check for func()!==false

That's something to bring up for discussion but right
now it's not how we document functions.  Only resource
should be listed there.

I like your idea of more structure.  Right now each manual
entry is full of <notes>'s, parameter descriptions can
sometimes get lost, and what the function does on failure
is also not structured.  During the phpdoc meeting awhile
back there was discussion of each manual entry having
a CHANGELOG but that's only part of it.

Here's a rough example (it's late, forgive me):

function in_array:

 --------------------------------------------------------------
 Parameter | Description                   | Notes
 --------------------------------------------------------------
 needle    | What is being searched for    | Became mixed in
           |                               | PHP 4.2.0
 haystack  | What we're searching in       |
 strict    | If set to true, the type will | Defaults to false
           | also be compared.             |
 ==============================================================
 On failure: returns false
 --------------------------------------------------------------

Seeing that below the proto might be useful and easy to read.
Anyway, something to think about :)

Regards,
Philip Olson

Reply via email to