PHP global variable access inside the class

by Ranganathan 2013-02-27 10:38:33

PHP global variable access inside the class



<?php
define('MYCONST', 'varname');
$varname = array("This is varname", "and array?");

class Myclass {
public $classvar;
function Myclass() {
$this->classvar =& $GLOBALS[MYCONST];
}
function printvar() {
echo $this->classvar[0];
echo $this->classvar[1];
}
};

$myobj = new Myclass;
$myobj->printvar();
?>

1163
like
0
dislike
0
mail
flag

You must LOGIN to add comments