dongshi2141 2012-05-11 12:31
浏览 74
已采纳

确定使用parent :: __ construct()的子类;

I have a situation where I need to pass the name of the child class back to the parent class in order to take some action.

The way I have it set up at the moment is:

class SomeParentClass {

    public function __construct($c = false){
        ...
    }

}

class SomeChildClass extends SomeParentClass {

    public function __construct(){
        parent::__construct(__CLASS__){
            ...
        }
    }

}

This will pass the name of the child class back to the parent, but if the child class does not do this then the variable $c will retain the bool value false.

It works, it makes sense, but is this the cleanest way to do this? Is there a way to auto detect which child class has called parent::__construct() without passing it as a variable?

Many thanks

  • 写回答

3条回答 默认 最新

查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题