answersLogoWhite

0


Best Answer

Problem with using global variables in php is that they lose the the assigned value in a different php file. They only keep the global variable value in the php file in which they are declared.

Instead of globals try and use $_SESSION or $_COOKIE to keep value intact across different php files in a project

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: When should globals be used in PHP?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is register globals in php?

Globals (global variables) are variables which are valid globally, which means they are available not only in a single function but "generally" throughout the script. register_globals is a switch which is defined in php.ini activating/deactivating this behavior. Since register_globals and the concept of globals is said to be removed for PHP6, it is advised to keep globals off and do not use global variables at all.


Why after installing PHP can it happen that you are able to run PHP functions but not to pass variables?

There are many things that can stop your variables from passing between your forms and your php scripts. One common reason is that your php configuration file is not configured to pass your form variables as globals, and instead passes them through the $_GET and $_POST superglobals. So, for example, if you form is as such: <form method="post"> <input name="whatever"> </form> Your php script would access the variable $whatever through the $_POST superglobal. $whatever = $_POST['whatever'];


Why should you use PHP and not JSP?

Firstly, this is wrong question. The right one would be WHEN should you use PHP, not JSP? or, WHEN should you use PHP and WHEN JSP?


Which language is used more for websites PHP or ASP.net?

Php


What is the use of a question mark in php?

It is used to tell the sever to use the PHP parser. To begin php you must use <?php, and to end it, it is ?>.


How does PHP function in applications?

in php used for one typ website


What file extension is used to save a php file after code has been written into it?

The file extension for PHP is .php


Why are you getting this warning this php file is out of date please contact cms support?

One of the possible scenarios is php file which is used is outdated. Major CMS vendors generally specify the php version which can be used to code. Use that version or above and the error message should leave automatically


What coding languages should Web Designers know?

PHP is now one of the most frequently used


Is PHP a drug?

PHP is a programming language. You may be thinking of PCP, or a-PHP (a-Pyrrolidinobutiophenone).


Where does PHP used?

PHP is a Server side scripting language used for web development.The programs in php will be run on the server and only the output is sent to the internet browser.


What is new in PHP?

PHP is a recursive acronym for "PHP: Hypertext Preprocessor" created by The PHP Group. PHP is a widely used server-side scripting language and the general purpose of PHP is to create dynamic Web Pages. For more information, visit the PHP website.