php中的类替换

有什么方法可以使它工作吗?见例子:
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 ::我知道我可以使用特殊的静态方法,但……

你需要一家汽车厂来制造新车;这不是JavaScript

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...