declaring instance variables
Posted: Fri Oct 22, 2010 11:37 pm
I can't find anything about this, I just want to know if this is a valid line:
Code: Select all
private $var1, $var2, $var3;A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
private $var1, $var2, $var3;Code: Select all
<?php
class varTest
{
private $a, $b, $c;
function isVarSet($var)
{
return isset($this->$var);
}
function otherTest($var)
{
var_dump($this->$var);
}
}
//object
$varTest = new varTest();
//see what's in it
var_dump($varTest);
//check if isset()
var_dump($varTest->isVarSet('a'));
var_dump($varTest->isVarSet('b'));
var_dump($varTest->isVarSet('c'));
//check undeclared variable
$varTest->otherTest('d');