X returns (value +3), and Y returns (value * 2)
With a value of 4, this means (4+3) * (4*2) = 7 * 8 = 56 .
Although functions are not limited in scope (which means you can safely define "socket definitions"), this specific example is error prone:
1) You cannot call y() before calling x() , because the function y() will not actually be defined until x() executes once.
2) Calling x() twice will force PHP to override the function y() , which will lead to a fatal error:
Fatal error: cannot override y ()
The solution to both issues would be to split the code, so that both functions are declared independently of each other:
function x ($y) { return($y+3); } function y ($z) { return ($z*2); }
It is also more readable.
Duroth Oct 27 '09 at 15:24 2009-10-27 15:24
source share