【发布时间】:2013-02-25 10:49:56
【问题描述】:
所以我是面向对象编程领域的新手,我目前正面临这个问题(代码中描述了一切):
<?php
class MyClass {
// Nothing important here
}
class MyAnotherClass {
protected $className;
public function __construct($className){
$this->className = $className;
}
public function problematicFunction({$this->className} $object){
// So, here I obligatorily want an $object of
// dynamic type/class "$this->className"
// but it don't works like this...
}
}
$object = new MyClass;
$another_object = new MyAnotherClass('MyClass');
$another_object->problematicFunction($object);
?>
谁能帮帮我?
谢谢,Maxime(来自法国:对不起我的英语)
【问题讨论】:
-
你不能使用{$this->className},检查$object with instanceof in questionsFunction
-
你想用这个实现什么?自动加载器?
标签: php class function dynamic arguments