Pregunta

This is regarding the PHP global variables. Does it mean the global variables are simply assigned values through the HTTP request(ie: Varaibles where pre-existing but without values), or that the variables are "instantiated" and assigned values(ie: variable where not pre-existing in script)? I am yet to see any text which explains.

¿Fue útil?

Solución

PHP's register_globals will create the appropriate global variables and assign values to them. Note that it's probably a really bad idea to use register_globals, since it poses a security risk. It's better to use the superglobal arrays $_POST, $_GET and $_COOKIE.

Otros consejos

registering globals simply means the process of registering various request variables as globally available. However, "register" in this case differs fundamentally from "assign" or "set" because the globals are inherently linked to their superglobal key counterparts (or "registered" as an alias), perhaps best summarized by this snippet of code:

// register_globals is on
$_POST["username"] === $username; // true

$username = "foo";
$_POST["username"] === $username; // *still* true

$_POST["username"] = "bar";
$_POST["username"] === $username; // *still* true

That is, changing one will change the corresponding superglobal key. Of course, this behavior should not be relied upon — if you're using register_globals in the first place, you're doing something wrong.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top