Code: Select all
class simple{
$property1=3
}it would be something like this i suppose:
Code: Select all
$obj=new simple;
$var='property1';
$value = 7;
$obj->$var=$value;Thanks in advance..
Moderator: General Moderators
Code: Select all
class simple{
$property1=3
}Code: Select all
$obj=new simple;
$var='property1';
$value = 7;
$obj->$var=$value;Code: Select all
class myClass
{
var $property = 0;
function setProperty($value)
{
$this->property = $value;
}
function getProperty()
{
return $this->property;
}
}
$obj = new myClass();
echo $obj->getProperty(); // 0
$obj->setProperty(12);
echo $obj->getProperty(); // 12
$obj->setProperty('foo');
echo $obj->getProperty(); // fooCode: Select all
class myClass
{
var $property = 0;
function setProperty($value)
{
$this->property = $value;
}
function getProperty()
{
return $this->property;
}
}
$obj = new myClass();
echo $obj->getProperty(); // 0
$global_value = &$obj->property; //Create a reference (pointer)
echo $global_value; // 0
$global_value = 7;
echo $global_value; // 7
echo $obj->getProperty(); // 7Code: Select all
array( propertyname1 => propertyvalue1,
propertyname2 => propertyvalue2,
)Code: Select all
foreach ($config as $key => $value){
$cbx->$key=$value;
}Code: Select all
class myClass
{
var $foo = 0, $bar = 0;
function addSomeNewProperties($array)
{
foreach ($array as $key => $value)
{
$this->$key = $value;
}
}
}
$obj = new myClass();
print_r($obj);
/*
myClass Object
(
[foo] => 0
[bar] => 0
)
*/
$array = array ( 'one' => 1, 'two' => 2 );
$obj->addSomeNewProperties($array);
print_r($obj);
/*
myClass Object
(
[foo] => 0
[bar] => 0
[one] => 1
[two] => 2
)
*/