【发布时间】:2013-03-03 01:42:16
【问题描述】:
这里有几个sn-ps:
-
重写构造函数方法有一个额外的参数。
class Cat { function __construct() {} } class Lion extends Cat { function __construct($param) {} } -
覆盖(常规)方法有一个额外的参数。
class Cat { function doSomething() {} } class Lion extends Cat { function doSomething($param) {} }
第一个会起作用,而第二个会抛出Declaration of Lion::doSomething() should be compatible with that of Cat::doSomething()。
为什么对构造方法持特殊态度?
【问题讨论】:
标签: php oop constructor