我希望按功能在类中创建新变量:
WaitForSingleObject(ghMutex, INFINITE)
示例:
CLASS book{
public function set($name){
newvar($name);
}
}
function newvar($str){
***????
/// what is code for here***
}
结果:
$x = new BOOK();
$x->set('title');
$x->title = 'jack';
echo 'book title is: ' . $x->title;
echo '<br>-----------------------------<br>';
$x->set('writer');
$x->writer = 'tom';
echo 'book writer is: ' . $x->writer;
答案 0 :(得分:1)
它的php :)
CLASS book{
public function set($name){
$this->$name = null;
}
}
或者甚至使用下面的代码,您可以动态添加属性
$x = new book();
$x->writer = 'tom';