I would like to know if there is a way to access a variable defined in an other file from a class in PHP.
Example :
file_01.php
<?php
$a = 42;
?>
file_02.php
<?php
require_once('file_01.php');
class mnyClass
{
private $myVar;
function __construct($var = $a)
{
$this->myVar = $var;
}
function getVar()
{
return $this->var;
}
function setVar($var)
{
$this->myVar = $var;
}
}
?>
Obviously, my class is more complicated. I have chosen this example for a better comprehension of what I try to do ;)
Thank you in advance.
define()method does not take an array as parameter. I knew the$GLOBALSvariable but it can't be used in constructor parameters : / So, I resign to use $GLOBALS in my constructor with NULL tests on parameters.