PHP中很少使用却功能强大的函数
call_user_func_array — 让参数以数组的形式调用一个函数
call_user_func — 调用一个存在的函数
create_function — 建立一个函数
func_get_arg — 获取函数中某个参数的值
func_get_args — 获取函数的所有参数并组成数组
func_num_args — 获取一个函数的参数个数
function_exists — 判定一个函数是否存在
get_defined_functions — 获取已有的函数信息
register_shutdown_function — 注册一个页面载入完成后运行的函数
register_tick_function — 注册一个按要求调用的函数
unregister_tick_function — 取消一个按要求调用的函数
get_defined_functions可以获取所有的PHP函数和自定义的函数:
function a(){}
$b = get_defined_functions();
print_r($b);
//也许会显示1000多个已定义了的函数:)
?>
function_exists函数判定一个函数是否存在(可以是PHP函数,也可以是自定义函数)。
if (function_exists('a')) {
echo "yes";
} else {
echo "no";
}
function a(){}
// 显示 yes
?>
call_user_func函数类似于一种特别的调用函数的方法,使用方法如下:
function a($b,$c)
{
echo $b;
echo $c;
}
call_user_func('a', "111","222");
call_user_func('a', "333","444");
//显示 111 222 333 444
?>
调用类内部的方法比较奇怪,居然用的是array,不知道开发者是如何考虑的,当然省去了new,也是满有新意的:
class a {
function b($c)
{
echo $c;
}
}
call_user_func(array("a", "b"),"111");
//显示 111
?>
call_user_func_array函数和call_user_func很相似,只不过是换了一种方式传递了参数,让参数的结构更清晰:
function a($b, $c)
{
echo $b;
echo $c;
}
call_user_func_array('a', array("111", "222"));
//显示 111 222
?>
call_user_func函数和call_user_func_array函数都支持引用,这让他们和普通的函数调用更趋于功能一致:
function a(&$b)
{
$b++;
}
$c = 0;
call_user_func('a', &$c);
echo $c;//显示 1
call_user_func_array('a', array(&$c));
echo $c;//显示 2
?>
func_num_args函数可以获取函数接受到参数的数量:
function a()
{
echo func_num_args();
}
a(111, 222, 333);
//显示 3
?>
func_get_arg函数可以获取某一个传递过来参数的值,在下面的例子中,在函数中并没有具体说明有哪些参数会被接受,利用func_get_arg还可以获取额外的参数:
function a()
{
echo func_get_arg(1);
}
a (111, 222, 333);
//显示 222
?>
- 共2页:
- 上一页
- 1
- 2
- 下一页

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an
