note 83127 deleted from language.functions by googleguy

From: Date: Sat, 19 Jan 2013 03:39:23 +0000
Subject: note 83127 deleted from language.functions by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193212@lists.php.net to get a copy of this message
Note Submitter: vameza at gmail dot com ---- 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.

« previous php.notes (#193212) next »