我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

你能知道固有的孩子名字吗?

I have a clase Base in PHP for inherit it to many children classes, managing errors into Base class, I try to print in screen where the error occurs, Can I get the child class name to show in the error during the Exception in Base parent Class?

Yes you can using get_class()

class Base{
    public function printBase(){
        echo get_class($this);
    }
}

class Ext extends Base{}

$ext = new Ext();
$ext->printBase(); //Output: Ext

The function get_called_class() resolve my problem, this throws the name of the class who is calling. http://php.net/manual/es/function.get-called-class.php

近期文章

  • JQuery验证和真人Captcha问题
  • PHP - 将每个变量变量传递给new foreach
  • Prestashop 1.6:无法在制造商页面中显示制造商徽标
  • Mediawiki:oojs-ui.styles.icons模块导致500服务器错误
  • Paypal IPN重试然后失败,没有Http响应代码
  • 使用嵌套的AJAX函数将新数据插入MYSQL
  • 我可以在带有别名的cakephp上加载插件吗?
  • 致命错误:“'在非对象上调用成员函数prepare()'”
  • 动态JSON输出
  • 第二栏没有显示[关闭]
  • 使用wamp找不到文件
  • Laravel在日期之间
  • CURL Ajax - XML响应 - Charset
  • Woocommerce订阅字符串
  • 在mysql数据库中存储下拉列表
  • 减少woocommerce摘录长度?
  • PHP + SQL成绩簿更新多行
  • 原始文本作为MySQL的替代品
  • 如何强制Laravel生成https链接?
  • 在ftp_put上调整图像大小(创建缩略图)

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华