有什么办法让它工作吗?见例子:
class car {
function __construct($type){
switch ($type) {
case 'big' : return new big_car();
case 'small' : return new small_car();
}
}
function whatisit () {
echo "this is car ;( \n";
}
}
class big_car extends car {
function __construct(){}
function whatisit () {
echo "this is big car ;) \n";
}
}
class small_car extends car {
function __construct(){}
function whatisit () {
echo "this is small car ;) \n";
}
}
所以目标是以这种方式使用它:
$mycar = new car('big');
$mycar->whatisit(); // i want it to say that it's big
我很想这是不好的方式,它不能以这种方式工作,但也许有一个技巧?
PS:: 我知道我可以为此使用特殊的静态方法,但是......