How PHP uses global variables

Source: Internet
Author: User
PHP Global Variables

   


The result is no output, how should global variables be defined and used?


Reply to discussion (solution)

$VFP _oledb_cstring= "Provider=vfpoledb.1;data source=d:/testoledb; Collating Sequence=machine ";
Testgol ();

function Testgol () {
Global $VFP _oledb_cstring;
echo $VFP _oledb_cstring;
}

It is not recommended to use the Global keyword, or to use the $globals Super global variable.

Put a yac on it. Shared memory between processes, very useful.

Do I need to declare it again at the time of invocation? .

This string is used to declare. The directory location of the VFP table, I want to use it as a configuration file to include
It is then used in the various FUNCTION of a PHP file to achieve this effect. It should be better to use that method.

You can also use $global Super global variables
$VFP _oledb_cstring= "Provider=vfpoledb.1;data source=d:/testoledb; Collating Sequence=machine ";
Testgol ();

function Testgol () {
echo $GLOBALS [' vfp_oledb_cstring '];
}

If your string is fixed, you can define it as a constant, and the range of constants is global. The constant can be accessed anywhere in the script without a tube-in-action area.

Using the constant problem is solved. Thank you for your trouble.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.