First, pseudo-type
There are three types of PHP pseudo-types, namely: 1,mixed mixed type. 2,number the numeric type. The 3,callback callback type.
1,mixed Mixed type:
Mixed shows that a parameter can accept many different types, but not all of them.
2,number Number Type:
The number parameter can accept an integer integer and float floating point type.
3,callback Callback Type:
For example, the Call_user_func () function can receive a user-defined function as a parameter, which is a built-in function of PHP. The callback function can be either a function or a method of an object, and the method of a static class can also be used. A PHP function is passed with a function name string that can pass any built-in or user-defined functions, in addition to the language structure such as array (), Echo (), Empty (), eval (), exit (), Isset (), list (), print (), Unset () and so on.
If you want to pass in an object's method, it needs to be passed as an array, the array subscript 0 is the object name, and the subscript 1 is the method name. If there is no static class that is instantiated as an object, to pass its method, replace the object name indicated by the array 0 subscript with the name of the class.
In addition to ordinary user-defined functions, you can use Create_function to create an anonymous callback function.
Example::
[PHP]View PlainCopy
- <?php
- //Normal callback function
- function My_callback_function () {
- echo "My is callback function.";
- }
- //callback method
- class myclass{
- static function Mycallbackmethod () {
- echo "My is callback method.";
- }
- }
- //num1: callback function
- Call_user_func (' my_callback_function ');
- //num2: Methods of static Classes
- Call_user_func (Array (' MyClass ',' Mycallbackmethod '));
- //num3: Object Methods
- $obj = new MyClass ();
- Call_user_func (Array ($obj,' Mycallbackmethod '));
- //num4: Methods of static classes (5.3.0 or more)
- Call_user_func (' Myclass::mycallbackmethod ');
- //NUM5: Relative static method invocation
- class A {
- public static function who () {
- echo "A";
- }
- }
- class B extends A {
- public static function who () {
- echo "B";
- }
- }
- Call_user_func (Array (' B ',' parent::who ')); //output B
- //NUM6: Incoming parameters when called
- function test ($a,$b) {
- echo $a;
- echo $b;
- }
- Call_user_function (' test ',' 1 ',' 2 '); //Output 1 2
- //NUM7: Calling a class method to pass in a parameter
- Class A () {
- function B ($c) {
- echo $c;
- }
- }
- Call_user_func (Array (' a ',' B '),' 1 '); //Output 1
- //num8:call_user_func_array is similar to Call_user_func, except that it is a way to pass parameters to make the parameter structure clearer:
- function A ($b,$c) {
- echo $b;
- echo $c;
- }
- Call_user_func_array (' A ',array (' 1 ',' 2 ')); //Output 1 2
- //NUM9: Calling class internal methods with Call_user_func_array
- class A () {
- function A ($b,$c) {
- echo $b;
- echo $c;
- }
- }
- Call_user_func_array (Array ('a ',' a '),Array (' 1 ',' 2 ')); //Output 1 2
- both the//num10:call_user_func function and the Call_user_func_array function support references, which makes them more functionally consistent with normal function calls:
- function A ($b) {
- $b + +;
- }
- $c = 0;
- Call_user_func (' A ',$c); //Output 1
- Call_user_func (' A ',array ($c)); //Output 2
[PHP]View PlainCopy
Second, pseudo-variable
$ in PHP ... The meaning of a pseudo-variable, indicating, and so on, when a function can accept any parameter, use this variable name.
PHP pseudo-type and pseudo-variables