Tuesday, 30 October 2012

Globals why should we avoid them in PHP

I don't remember when was the last time I used the keyword global in php to allow a function to use a global variable. Why did I do it today? Because I built a prototype and wanted a quick solution, but the function is evoked by an event, hence the value of the content can change unexpectedly.

I think it taught me not to take shortcuts, as the consequences can be bad.
I took it from the example of XML Element Structure on the official php website.