You are here: Re: Outside variables needed inside class « PHP Programming Language « IT news, forums, messages
Re: Outside variables needed inside class

Posted by Jerry Stuckle on 05/18/07 22:10

Justin Voelker wrote:
> Can anyone explain to me why globals are so bad? I have a $phpEx
> variable in my main config file and i use "global $phpEx" inside of
> certain functions that return links so I don't have to change a
> hundred links if I change my php extension to something else (php4,
> php5). Thanks for the great help everyone! Now if I can just figure
> out how to implement your solutions...
>

The biggest problem is you might change the global somewhere due to a
bug in the program - and have to spend hours trying to figure out where
you went wrong.

A secondary problem is that when you modify your code you can
unintentionally insert bugs into the code by changing the value.

Another potential problem occurs when you include another package in
your scripts which just happens to use the same global - what does it
do? This can even be one of your own scripts, added because you
rearranged the code.

Passing the values as parameters allows you to control what's going on.
And if you have to change the value in your function, pass by reference.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация