所以我在面向对象编程的世界新和我目前面临这个问题(一切都在规范中描述):PHP:函数参数必须与动态类名称的对象
<?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);
?>
灿任何人都帮助我?
感谢,马克西姆(法国:对不起,我的英语)
你不能使用{$ this-> className},在有问题的函数中用instanceof检查$ object – sanj 2013-02-25 10:55:22
你想用这个来实现什么?自动加载磁带机? – 2013-02-25 10:57:00