zoukankan      html  css  js  c++  java
  • spl_autoload_register array参数

    spl_autoload_register

    (PHP 5 >= 5.1.2)

    spl_autoload_register — 注册给定的函数作为 __autoload 的实现

    说明 ¶

    bool spl_autoload_register ([ callable $autoload_function [, bool $throw = true [, bool$prepend = false ]]] )
     
    callable定义:

    Callback 回调类型 ¶

    自 PHP 5.4 起可用 callable 类型指定回调类型 callback。本文档基于同样理由使用 callback 类型信息。

    一些函数如 call_user_func() 或 usort() 可以接受用户自定义的回调函数作为参数。回调函数不止可以是简单函数,还可以是对象的方法,包括静态类方法。

    传递 ¶

    一个 PHP 的函数以 string 类型传递其名称。可以使用任何内置或用户自定义函数,但除了语言结构例如:array()echoempty()eval()exit()isset()list()print 或 unset()

    一个已实例化的对象的方法被作为数组传递,下标 0 包含该对象,下标 1 包含方法名。

    静态类方法也可不经实例化该类的对象而传递,只要在下标 0 中包含类名而不是对象。自 PHP 5.2.3 起,也可以传递'ClassName::methodName'

    除了普通的用户自定义函数外,create_function() 可以用来创建一个匿名回调函数。自 PHP 5.3.0 起也可传递 closure给回调参数。

    <?php 
    
    // An example callback function
    function my_callback_function() {
        echo 'hello world!';
    }
    
    // An example callback method
    class MyClass {
        static function myCallbackMethod() {
            echo 'Hello World!';
        }
    }
    
    // Type 1: Simple callback
    call_user_func('my_callback_function'); 
    
    // Type 2: Static class method call
    call_user_func(array('MyClass', 'myCallbackMethod')); 
    
    // Type 3: Object method call
    $obj = new MyClass();
    call_user_func(array($obj, 'myCallbackMethod'));
    
    // Type 4: Static class method call (As of PHP 5.2.3)
    call_user_func('MyClass::myCallbackMethod');
    
    // Type 5: Relative static class method call (As of PHP 5.3.0)
    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')); // A
    ?>

  • 相关阅读:
    Day2 三级菜单
    python 练习之购物车
    Day1 登录接口脚本 login.py
    第十周学习进度
    浪潮之巅阅读笔记三
    浪潮之巅阅读笔记二
    浪潮之巅阅读笔记一
    第九周学习进度
    构建执法阅读笔记六
    构建之法阅读笔记五
  • 原文地址:https://www.cnblogs.com/lein-wang/p/4349637.html
Copyright © 2011-2022 走看看