On November 19, 2001 07:26 am, Simone Cortesi wrote:
> Hi,
>
> I vas translating the following :
>
> <!ENTITY return.falseproblem '<warning><simpara>This function may
> return &false;, but may also return a value evaluating to &false; in
> a simple if statement. Please use <link
> linkend="language.operators.comparison">the === operator</link> for
> testing the return value of this
> function.</simpara></warning>'>
>
> found in 'language-snippets.ent', but i cant get the meaning of this
> sentence: "but may also return a value evaluating to &false; in a
> simple if statement".
The sentence is attempting to explain that some functions
may return values that can be interpreted as false within
a conditional block.
Take the following example:
$str = 'abcdef';
$chr = 'a';
if ($pos = strpos ($str, $chr) )
echo "'$chr' found in '$str' at position $pos";
'a' definitely exists in the string. However, since strpos() returns
0 - the position that 'a' is at - the if statement considers
the result to be false.
For cases like this, the user needs to use code more like:
$str = 'abcdef';
$chr = 'a';
if (FALSE !== ($pos = strpos ($str, $chr)) )
echo "'$chr' found in '$str' at position $pos";
FTM, they could also do:
$str = 'abcdef';
$chr = 'a';
$pso = strpos ($str, $chr);
if ( is_int ($pos) )
echo "'$chr' found in '$str'";
--
Zak Greant
PHP Quality Assurance Team
http://qa.php.net/
"We must be the change we wish to see." - M. K. Ghandi