我有一個參數數組傳遞給參數個數可變的方法。我完全不知道該怎麼做。嘗試在函數上調用參數數組
class Entity {
protected $realObject;
public function __call($name, $arguments) {
// just call this method on the $property, otherwise redefine the method
// error_log("Called $name");
// TODO support variable numbers of arguments
$argc = count($arguments);
if($argc > 0) {
return $this->realObject->$name($arguments[0]);
} else {
return $this->realObject->$name();
}
}
}
我一直在尋找各種各樣的做這件事的辦法,但似乎無法制定出翻動數組變量變量的一種方式。
您傳遞給'_call'方法的第一個參數始終是'$ this-> realObject'的屬性? 'realObject'是你在Entity構造函數中注入的類實例嗎? – amenadiel
是的,這是其他人的課程的抽象。我的對象是它們對象的副本。 – Badger