codice:
class Pluto {}
class Pippo {
// vanno [sono costanti]
var $nulla = null,
$intera = 1,
$floattante = 1.2,
$booleana = true,
$stringa = "ciao",
$array = array(null, 1, 1.2, true, "ciao");
/** non vanno
var $pluto = new Pluto(),
$anno = date("Y"),
$array2 = array($this->stringa, "... altro"),
$function = create_function('', 'return true;');
// */
//** ma puoi fare così
var $pluto,
$anno,
$array2,
$function;
// constructor
function Pippo() {
$this->pluto = new Pluto();
$this->anno = date("Y");
$this->array2 = array($this->stringa, "... altro");
$this->function = create_function('', 'return true;');
}
// */
/** ... o per avere un costruttore PHP5 anche in PHP 4 ...
function __construct() {
$this->pluto = new Pluto();
$this->anno = date("Y");
$this->array2 = array($this->stringa, "... altro");
$this->function = create_function('', 'return true;');
}
function Pippo() {
$construct = array();
for($i = 0, $j = func_num_args(); $i < $j; $i++)
array_push($construct, '$_'.$i.'=func_get_arg('.$i.')');
eval('$this->__construct('.implode(',', $construct).');');
}
// */
function showYear() {
echo 'Anno: '.$this->anno.'
';
}
}
$pippo = new Pippo();
$pippo->showYear();
// questa inveve non va, non potendo impostare $anno
// Pippo::showYear(); // Anno:
// Notice: Undefined variable: this in test.php on line 438