By Volume4
via php.dzone.com
Published: Aug 28 2008 / 09:44
Anyone who has worked with PHP knows that it is extremely permissive with variables and their types. There's no need to declare variables, not even at class level, and data types cannot really be enforced. This is one of the greatest strengths of weakly typed dynamic languages, but it can be easily used the wrong way.
Comments
OIS replied ago:
The solution is to put as much code as possible into different specific functions/methods so this wont be a problem.
killerweb replied ago:
Never say, "this is better than that". In code it's all about context, in some cases reusing vars can be clean and easy to follow. And in some cases it's not. In the example, it makes total sense not to reuse the fruit var, but thats just one case. Generalizing is never a good thing.
ahot replied ago:
Funny :)
I can give simpler example, never do:
$i=1;
...
$i=2;
How knows... May be you'll want to use old value of $i :)
Voters For This Link (14)
Voters Against This Link (3)