How to disable global variables.

I have a project id and client id , which are sessions in php that are passed in JSON format. They are stored in the global variables id_p and id_c , so I can do several attachments and updates, selects, etc. With these identifiers.

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

  • Can I pass null value from php to global vars to reset them?
  • Is there a better way to do what I want?
  • How to save php values ​​to php only if a file is required? The files in which the queries are executed are in separate files.
+4
source share
2 answers

Do they set to null or does undefined do what you are looking for?

 id_p = null; id_c = null; 
+3
source

To really disable them, use

 unset ( $GLOBALS['id_p'] ); 

This also works in functions.

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

+1
source

Source: https://habr.com/ru/post/1387826/


All Articles