PHP 手冊
上一頁 | 章 12.Functions | 下一頁

# Variable functions

PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth.

示範 12-1.Variable function example

`<?php function foo() { echo "In foo()<br>\n"; } function bar( $arg = '' ) { echo "In bar(); argument was '$arg'.<br>\n"; } $func = 'foo'; $func(); $func = 'bar'; $func( 'test' ); ?>`

上一頁 | 最開頭 | 下一頁
old_function | 上一層 | 類別和物件