Php - Variable

Card Puncher Data Processing

About

This page gather information about variable management in PHP.

Scope

The _ underscore is just a cosmetic syntax to set the public/private/protected properties.

E.g.

  • private _arr = array()
  • or public arr = array()

Global

Foo in global scope

  • Get
$GLOBALS["foo"]
  • Set
$GLOBALS["foo"]="bar";
// or 
global $foo;
$foo = "bar"

Print

print_r with true

Reference

Reference type management

Passing a Reference Variable

function myFunction($name, &$data) {

        $this->name = $name; // name data will be copied
        $this->data = &$data; // whereas this->data will get a reference (ie location) to $data

}

Returning a Reference Variable

function &myFunction($name, &$data) {

        return $this->data; // Returning a reference because of the & at the beginning of the function

}







Share this page:
Follow us:
Task Runner