About PHP Global custom variable Solution!

Source: Internet
Author: User
The concept is still unclear, use do not understand, stupid person!!!
I want to write a whole station global variable, in which class can be shared
For example, I initialize the global variable in Class A, then I can read and write in other classes to share the variable, ask which boss write an example, grateful!!!


Reply to discussion (solution)

Use Session or Cookie

Then you just write a base class, declare a variable ...

Then you just write a base class, declare a variable ...

For example, thank you!!!

Use the global reference in the method of the class
Like what

$a = "123"; class dd{   function Show () {     global $a;     $a = "CC";   }} Class cc{   function Show () {     global $a;     return $a;   }} $d = new DD (), $d-and show (), $c = new CC (), Echo $c-show ();

You can see that the result of the final output is CC

 
  Initname ("Phper");//Instantiate class two $b = new Son2class ();//Get $name value $name = $b->index ();//Initialize a Son1class value in $name, can also be called in Son2class. Echo $name; Output Phper
  • 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.