__construct() vs SameAsClassName() for constructor in PHP

后端 未结 11 2753
南笙
南笙 2020-11-28 09:55

Is there any advantage to using __construct() instead of the class\'s name for a constructor in PHP?

Example (__construct):



        
11条回答
  •  臣服心动
    2020-11-28 10:06

    The best advantage of using __contruct() instead of ClassName() is when extending classes. It is much easier to call parent::__construct() instead of parent::ClassName(), as it is reusable among classes and the parent can be changed easily.

提交回复
热议问题