-3
類
使用我想通過函數來創建類的新變量:如何在功能定義變量和
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;
結果:
你爲什麼要這樣來做任何特別的原因?當你已經有__get/__ set/etc魔術方法時,爲什麼你要使用全局函數? –