Link Details

Link 107628 thumbnail
User 71517 avatar

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.
  • 15
  • 3
  • 1146
  • 387

Comments

Add your comment
User 275943 avatar

OIS replied ago:

0 votes Vote down Vote up Reply

The solution is to put as much code as possible into different specific functions/methods so this wont be a problem.

User 270877 avatar

killerweb replied ago:

0 votes Vote down Vote up Reply

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.

User 328104 avatar

ahot replied ago:

-1 votes Vote down Vote up Reply

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 :)

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.