Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unset global variables.

I have an id of a project and an id of a client that are sessions in php that are passed in JSON format. These are stored in global variables id_p and id_c so I can do multiple inserts and updates selects etc. with those ids.

When the user selects another project or changes the page, I need to unset these variables.

  • Can I pass a null value from php to the global vars to reset them?
  • Is there a better way to do what I want?
  • How could I store the php values on php only if the file is required? The files where the queries take place are on separate files.
like image 594
Samuel Lopez Avatar asked Dec 24 '11 01:12

Samuel Lopez


People also ask

How do you unset a global variable?

If unset() is called inside a user-defined function, it unsets the local variables. If a user wants to unset the global variable inside the function, then he/she has to use $GLOBALS array to do so. The unset() function has no return value.

Can you delete global variables?

Deleting Global Variables. You can delete global variable definitions from Integration Server using Integration Server Administrator. If you delete a global variable that is used by a flow service, while executing the flow service, Integration Server will throw an exception and stop the service execution.

How do you release a global variable in python?

To delete a global variable from inside a function:Use the global keyword to mark the variable as global inside of the function. Use the del statement to delete the variable.

How do you clear a global variable in C++?

you can put those variables in aclass , then create pointer to object of that class in the 1st place will use those variables then pass this pointer to every methode need those variables , don`t forget to delete the object when you will not use .


1 Answers

To really unset them, use

unset ( $GLOBALS['id_p'] );

This also works in functions.

Source: http://toscho.de/2012/php-unset-unterschied-global-globals/

like image 164
luckydonald Avatar answered Nov 15 '22 07:11

luckydonald