List Info

Thread: note 77445 added to functions.returning-values




note 77445 added to functions.returning-values
user name
2007-08-29 22:06:36
It took my some 30 minutes to figure out this strange thing
that I happened to have, wasn't aware of this before.
Posting here so that it might help for some of you as
well..

Let say you have a function that returns a 0 or 1:

function isValid(){
     if(true)
       return 1;
     else
        return 0;
}

In your code you should call this as:

if (someFunction == '0') { //mind quotes!
   // do something
}

it is very strange, but it didn't work for me when I tried
==0, and even when I tried if (!someFunction) .... I even
tried to have my function  return booleans as in 'return
false' and return 'true'.

I have PHP 4.4.6, 1.3.37 (Unix)

PS: don't know whether it is a bug, or normal behavior :/

Peace.
mm
----
Server IP: 69.147.83.197
Probable Submitter: 76.16.212.113
----
Manual Page -- http://www.php.net/manual/en/functions.returning-valu
es.php
Edit        -- https://master
.php.net/note/edit/77445
Del: integrated  -- h
ttps://master.php.net/note/delete/77445/integrated
Del: useless     -- http
s://master.php.net/note/delete/77445/useless
Del: bad code    -- htt
ps://master.php.net/note/delete/77445/bad+code
Del: spam        -- https:/
/master.php.net/note/delete/77445/spam
Del: non-english -- 
https://master.php.net/note/delete/77445/non-english
Del: in docs     -- http
s://master.php.net/note/delete/77445/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/77445
Reject      -- https://mast
er.php.net/note/reject/77445
Search      -- https://
master.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )