一、获取静态方法调用者的类名

方法一:
class foo {
static public function test() {
var_dump(get_called_class());
}
} class bar extends foo {
} foo::test();
bar::test(); 输出: string(3) "foo"
string(3) "bar" 方法二:
class Bar {
public static function test() {
var_dump(static::class);
}
} class Foo extends Bar { } Foo::test();
Bar::test(); Output: string(3) "Foo"
string(3) "Bar"

二、运用call_user_func_array代入对象作用域

<?php
function foobar ( $arg , $arg2 ) {
echo __FUNCTION__ , " got $arg and $arg2 \n" ;
}
class foo {
function bar ( $arg , $arg2 ) {
echo __METHOD__ , " got $arg and $arg2 \n" ;
}
} // Call the foobar() function with 2 arguments
call_user_func_array ( "foobar" , array( "one" , "two" )); // Call the $foo->bar() method with 2 arguments
$foo = new foo ;
call_user_func_array (array( $foo , "bar" ), array( "three" , "four" ));
?>

[PHP]获取静态方法调用者的类名和运用call_user_func_array代入对象作用域的更多相关文章

  1. php 获取静态方法调用的类名

    方法一: class foo { static public function test() { var_dump(get_called_class()); } } class bar extends ...

  2. JAVA中获取当前运行的类名,方法名,行数

    JAVA中获取当前运行的类名,方法名,行数 public static String getTraceInfo(){ StringBuffer sb = new StringBuffer(); Sta ...

  3. Java中获取运行代码的类名、方法名

    以下是案例,已运行通过 package com.hdys; /* * 1.获取当前运行代码的类名,方法名,主要是通过java.lang.StackTraceElement类 * * 2. * [1]获 ...

  4. WinAPI: GetClassName - 获取指定窗口的类名

    WinAPI: GetClassName - 获取指定窗口的类名 //声明: GetClassName( hWnd: HWND; {指定窗口句柄} lpClassName: PChar; {缓冲区} ...

  5. 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换

    [源码下载] 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换 作者:webabcd 介绍速战速决 之 PHP ...

  6. c# 在静态方法里,怎么能得到调用者的类名?

    System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); string name = st.GetFrame(1) ...

  7. PHP 获取当前所在的类名、方法名等

    PHP获取当前类名.方法名  __CLASS__ 获取当前类名  __FUNCTION__ 当前函数名(confirm)  __METHOD__ 当前方法名 (bankcard::confirm) _ ...

  8. python 动态获取当前运行的类名和函数名的方法

    一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...

  9. .NET使用StackTrace获取方法调用者信息

    前言 在日常工作中,偶尔需要调查一些诡异的问题,而业务代码经过长时间的演化,很可能已经变得错综复杂,流程.分支众多,如果能在关键方法的日志里添加上调用者的信息,将对定位问题非常有帮助. 介绍 Stac ...

随机推荐

  1. CentOS7.5脱机安装SQL Server 2017(NEW)

    发现搜到的都是在线下载安装的,都是只安装了mssql-server服务,没有mssql-server-agent服务.还以为linux下mssql没有agent服务呢.一番测试发现可以脱机安装,但是能 ...

  2. 通过FactoryBean配置Bean

    这是配置Bean的第三种方式,FactoryBean是Spring为我们提供的,我们先来看看源码: 第一个方法:public abstract T getObject() throws Excepti ...

  3. 操作docker容器

    Docker容器时镜像的一个运行实例,而镜像是静态的只读文件,容器带有运行时需要的可写文件层.如果认为虚拟机是模拟运行的一整套操作系统(包括内核.应用运行的环境和其他系统环境)和跑在上面的应用,那么D ...

  4. 简单了解uuid

    1.含义 UUID-Universally Unique IDentifiers,翻译过来就是“全局唯一标志符”. UUID到底是什么? UUID是一个标帜你系统中的存储设备的字符串,其目的是帮助使用 ...

  5. ORACLE表数据误删除的恢复方法(提交事务也可以)

    ORACLE表数据误删除的恢复方法(提交事务也可以) 缓存加时间戳 开启行移动功能:ALTER TABLE tablename ENABLE row movement 把表还原到指定时间点:flash ...

  6. 洛谷P1188PASTE题解

    题目 这个题主要是一个考分类讨论的模拟题,做这个提的时候首先要脑子清醒,才可以清楚地写出怎么模拟来. \(Code\) #include <iostream> #include <a ...

  7. 皮尔逊相关系数(Pearson Correlation Coefficient, Pearson's r)

    Pearson's r,称为皮尔逊相关系数(Pearson correlation coefficient),用来反映两个随机变量之间的线性相关程度. 用于总体(population)时记作ρ (rh ...

  8. Python3 与 C# 并发编程之~ 进程篇

      上次说了很多Linux下进程相关知识,这边不再复述,下面来说说Python的并发编程,如有错误欢迎提出- 如果遇到听不懂的可以看上一次的文章:https://www.cnblogs.com/dot ...

  9. selenium家族发展史

    什么是Selenium? Selenium 是专门为Web应用程序编写的一个验收测试工具.Selenium测试直接运行在浏览器中,支持的浏览器包括IE(7.8.9).Mozilla Firefox.M ...

  10. LeetCode 92. ReverseLinkedII

    #include <iostream> using namespace std; struct ListNode { int val; ListNode *next; ListNode(i ...