note 83127 added to language.functions
| From: | vameza at gmail dot com | Date: | Sun, 11 May 2008 23:15:38 +0000 |
| Subject: | note 83127 added to language.functions | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139289@lists.php.net to get a copy of this message | ||
An important thing that must be considered when using functions and references is that functions
that do not return any value at all, will indeed return NULL as result.
Carefull must be taken in order to avoid unexpected results, as show below:
<?php
function a($n)
{
return ( b($n) * $n );
}
function b(&$n){
++$n;
}
echo $a(5);
// The result is 0. Why?? Answer below...
?>
As the function b not return any value, the engine makes the function returns NULL. When is
performed a multiplication in function a, the returned value is converted to zero, and finally the
returned value from function a is zero as well.
I took long to realize this concept. An answer can be found in the Zend PHP5 Certification Study
Guide (PHP/architect´s publishing).
So, in conclusion, be carefull when using a function to perform operations. It must return a value.
----
Server IP: 69.147.83.197
Probable Submitter: 201.43.150.61
----
Manual Page -- http://www.php.net/manual/en/language.functions.php
Edit -- https://master.php.net/note/edit/83127
Del: integrated -- https://master.php.net/note/delete/83127/integrated
Del: useless -- https://master.php.net/note/delete/83127/useless
Del: bad code -- https://master.php.net/note/delete/83127/bad+code
Del: spam -- https://master.php.net/note/delete/83127/spam
Del: non-english -- https://master.php.net/note/delete/83127/non-english
Del: in docs -- https://master.php.net/note/delete/83127/in+docs
Del: other reasons-- https://master.php.net/note/delete/83127
Reject -- https://master.php.net/note/reject/83127
Search -- https://master.php.net/manage/user-notes.php