PHP: How to Pass child class __construct() arguments to parent::__construct()?

前端 未结 7 1243
-上瘾入骨i
-上瘾入骨i 2020-12-14 00:17

I have a class in PHP like so:

class ParentClass {
    function __construct($arg) {
        // Initialize a/some variable(s) based on $arg
    }
}
         


        
7条回答
  •  臣服心动
    2020-12-14 00:32

    Yeah, it's pretty bad practice to make a child class that uses different constructor arguments from the parent. Especially in a language like PHP where it's poorly supported.

    Of course, the generic way to pass a set of "whatever arguments we might ever want" in PHP is to pass a single argument consisting of an array of configuration values.

提交回复
热议问题