zoukankan      html  css  js  c++  java
  • php类知识----特别用法

    • spl_autoload_register注册
    <?php
    
    #spl_autoload_register-----这个例子是用来打印实例化类的类名
    function thereisagameoflove($classname)  #自定义函数 thereisagameoflove参数$classname是类的名字
    {
        echo $classname;  #打印类的名字
        //找到类文件并导入
        include "wenwa.php";   #下面use后面的类 定义在文件wenwa.php中
    }
    spl_autoload_register('thereisagameoflove');
    use 	rainningplan2cjmycoach; 
    $cpc = new mycoach();
    ?>

    输出结果:

    trainningplan2cjmycoach

    •  call_user_func  通过在参数中输入实例对象名,对象方法名,参数达到执行函数的目的 call_user_func_array([对象名,方法名],对象方法参数)
    <?php
    class mycoach
    {
        public function __construct($name,$age)
        {
            $this->name = $name;
            $this->age = $age;
        }
        public function introduce($name,$age)
        {
            echo "我是 ".$name." 今年 ".$age."
    ";
        }
        public function saymorning($name)
        {
            echo "good morning~ i'm ".$name;
        }
    }
    $cj = new mycoach('程劲',20);
    call_user_func([$cj,'saymorning'],'劲儿弟弟');
    ?>

    输出结果:

    good morning~ i'm 劲儿弟弟

    •  call_user_func_array 通过在参数中输入实例对象名,对象方法名,参数达到执行函数的目的 call_user_func_array([对象名,方法名],[对象方法参数1,对象方法参数2,......])
    <?php
    class mycoach
    {
    public function __construct($name,$age)
    {
    $this->name = $name;
    $this->age = $age;
    }
    public function introduce($name,$age)
    {
    echo "我是 ".$name." 今年 ".$age." ";
    }
    }
    $cj = new mycoach('程劲',20);
    call_user_func_array([$cj,'introduce'],['程劲',20])
    ?>

     输出结果:

    我是 程劲 今年 20

    • 对于普通函数,call_user_func_array, call_user_func可以这么用
    <?php
    function introduce($name)
    {
        echo "我是 ".$name."
    ";
    }
    function expertin($expert1,$expert2)
    {
        echo "擅长格斗技:".$expert1.",".$expert2;
    }
    call_user_func('introduce','劲儿弟弟');
    call_user_func_array('expertin',['泰拳','巴西柔术']);
    ?>

    输出结果:

    我是 劲儿弟弟
    擅长格斗技:泰拳,巴西柔术

    • 其他用法

  • 相关阅读:
    svn服务器安装
    flex 协同
    大尾端 小尾端
    UNIX下c语言的图形编程curses.h 函式库(2)
    vs2005设置
    client 连接 host —— 虚拟机
    fedora 连网问题。。
    pv ip uv
    checking for XML::Parser... configure: error: XML::Parser perl module is required for intltool
    UNIX下c语言的图形编程curses.h 函式库
  • 原文地址:https://www.cnblogs.com/saintdingspage/p/10964851.html
Copyright © 2011-2022 走看看