[PHP]获取静态方法调用者的类名和运用call_user_func_array代入对象作用域
一、获取静态方法调用者的类名
方法一:
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代入对象作用域的更多相关文章
- php 获取静态方法调用的类名
方法一: class foo { static public function test() { var_dump(get_called_class()); } } class bar extends ...
- JAVA中获取当前运行的类名,方法名,行数
JAVA中获取当前运行的类名,方法名,行数 public static String getTraceInfo(){ StringBuffer sb = new StringBuffer(); Sta ...
- Java中获取运行代码的类名、方法名
以下是案例,已运行通过 package com.hdys; /* * 1.获取当前运行代码的类名,方法名,主要是通过java.lang.StackTraceElement类 * * 2. * [1]获 ...
- WinAPI: GetClassName - 获取指定窗口的类名
WinAPI: GetClassName - 获取指定窗口的类名 //声明: GetClassName( hWnd: HWND; {指定窗口句柄} lpClassName: PChar; {缓冲区} ...
- 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换
[源码下载] 速战速决 (6) - PHP: 获取 http 请求数据, 获取 get 数据 和 post 数据, json 字符串与对象之间的相互转换 作者:webabcd 介绍速战速决 之 PHP ...
- c# 在静态方法里,怎么能得到调用者的类名?
System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(); string name = st.GetFrame(1) ...
- PHP 获取当前所在的类名、方法名等
PHP获取当前类名.方法名 __CLASS__ 获取当前类名 __FUNCTION__ 当前函数名(confirm) __METHOD__ 当前方法名 (bankcard::confirm) _ ...
- python 动态获取当前运行的类名和函数名的方法
一.使用内置方法和修饰器方法获取类名.函数名 python中获取函数名的情况分为内部.外部,从外部的情况好获取,使用指向函数的对象,然后用__name__属性 复制代码代码如下: def a():pa ...
- .NET使用StackTrace获取方法调用者信息
前言 在日常工作中,偶尔需要调查一些诡异的问题,而业务代码经过长时间的演化,很可能已经变得错综复杂,流程.分支众多,如果能在关键方法的日志里添加上调用者的信息,将对定位问题非常有帮助. 介绍 Stac ...
随机推荐
- 【Swift 4.2】uuid 取 hashCode(与 Java/Go/Kotlin 一致)
extension String { func hashCode() -> Int32 { let components = self.split(separator: "-" ...
- windows下redis安装及配置
1.简介: redis是一个高性能的key-value数据库:redis能读的速度为11万次/秒,写的速度是8.1万次/秒 redis支持丰富的数据类型:String, List, Hash(map) ...
- 基于struts2、hibernate、spring、shiro、MySQL的项目开发
使用maven管理jar包的依赖 < project xmlns = “ http://maven.apache.org/POM/4.0.0 ” xmlns :xsi = “ http://ww ...
- mysql常用权限命令、乱码及其他问题记录
用户管理 use mysql; 查看 select host,user,password from user ; 创建 create user xuhong IDENTIFIED by 'xuh ...
- powershell 函数, foreach中格式化
function testArg { $n = 1; if($args.Count -eq 0) { "No arg!" } else { $args | foreach {&qu ...
- HP 1010、 1020、 1022 、M1005激光打印机内部无卡纸,但机器仍提示卡纸?
HP 1010.1018.1020.1022.M1005激光打印机,硒鼓原装编号:Q2612A 1800页 ( A4纸,5%覆盖率).是办公桌面小型打印机中主流产品,故障率极小. 现有一台HP 10 ...
- SQL 中使用 WITH AS 提高性能
一.WITH AS的含义WITH AS短语,也叫做子查询部分(subquery factoring),可以让你做很多事情,定义一个SQL片断,该SQL片断会被整个SQL语句所用到.有的时候,是为了让S ...
- koa-router 后台路由管理框架
koa-router是koa框架配套的路由管理模块,对后台的接口分离出来. 首先引入koa和koa-router, 然后分批设置路由: 代码中的institution.modifyInsStatus是 ...
- animation 动画
语法 animation: name duration timing-function delay iteration-count direction fill-mode play-state ani ...
- python 爬虫之beautifulsoup(bs4)使用 --待完善
#!/usr/bin/env python # -*- coding:utf- -*- from bs4 import BeautifulSoup import requests url = 'htt ...