Welcome Guest, Not a member yet? Register   Sign In
Does CI unset variables in $GLOBALS ?
#1

[eluser]shanebonham[/eluser]
I'm sort of new to this, so my understanding may be flawed, but outside of CI, this seems to work:

Code:
$foo='bar';
echo $GLOBALS['foo'];

'bar' will be echoed. However, if I put the above in a CI controller's method, it doesn't work (I get an 'undefined index' notice). I know CI unsets some stuff, and I thought that was all handled by _sanitize_globals() in the Input class, but from what I can tell, it leaves $GLOBALS alone. I also see this in the docs: "Destroys all global variables in the event register_globals is turned on." Where does this happen?
#2

[eluser]shanebonham[/eluser]
It's worth pointing out that what I was originally trying to do was assign $foo outside of a function, and then use it inside the function after setting `global $foo;` (which didn't work).
#3

[eluser]InsiteFX[/eluser]
$GLOBALS is truned off by default in your php.ini file for security reasons!

They do not use it anymore...
#4

[eluser]shanebonham[/eluser]
Do you have a source for $GLOBALS being deprecated?

I get output from print_r($GLOBALS). I just don't get any of my variables.
#5

[eluser]WanWizard[/eluser]
http://php.net/manual/en/security.globals.php

This is the age of OOP. Do not use globals. not now. not ever. If your app requires globals, you've designed it wrong.
#6

[eluser]shanebonham[/eluser]
Thanks for the advice, but I'm just trying to understand CI better. Are you sure that the deprecation of the register_globals directive also means the deprecation of the $GLOBALS array? That isn't what the docs seem to be saying.
#7

[eluser]WanWizard[/eluser]
I don't think $GLOBALS will disappear soon, as that would mean the global keyword will no longer work too, which will break a lot of applications (including CI).

The rest of my statement still stands. Using globals is evil. period.




Theme © iAndrew 2016 - Forum software by © MyBB