php中的类替换
发布时间:2020-12-13 13:29:00 所属栏目: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 ext
有什么方法可以使它工作吗?见例子:
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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |