I have a class:
class Foo {
// Accept an assoc array and appends its indexes to the object as property
public function extend($values){
foreach($values as $var=>$value){
if(!isset($this->$var))
$this->$var = $value;
}
}
}
$Foo = new Foo;
$Foo->extend(array('name' => 'Bee'));
Now the $Foo
object has a public name
property with value Bee
.
How to change extend
function to make variables private ?
Edit
Using a private array is another way and definitely not my answer.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…