zoukankan      html  css  js  c++  java
  • call_user_func函数

    <?php
      2     class Person
      3     {
      4         private $name;
      5         private $age;
      6         function __construct($name,$age)
      7         {
      8             $this->age = $age;
      9             $this->name = $name;
     10         }
     11
     12         function getInfo()
     13         {
     14             return [$this->name,$this->age];
     15         }
     16     }
     17
     18     class Man
     19     {
     20         private $person;
     21         function __construct($person)
     22         {
     23             $this->person = $person;
     24         }
     25         function __call($method, $args){
     26             echo get_called_class().PHP_EOL;
     27             return call_user_func([$this->person,$method],...$args);
     28         }
     29     }
     30     $person = new Person('tom',11);
     31
     32     $man = new Man($person);
     33     $result = $man->getInfo();
     34     var_dump($result);//通过回调函数调用对象方法 (用于=>调用某些接口自带的方法 直接采用__call来间接调用对象方法)
    ~                                

  • 相关阅读:
    WPF Margin和Padding
    WPF Tab切换顺序设置
    WPF DataGrid DataGridTemplateColumn
    WPF CheckBox IsHitTestVisible
    WPF Tag
    WPF RadioButton
    WPF 用户控件(UserControl)
    WPF ToolTip
    Style Lessons in Clarity and Grace (11th Edition)中文翻译
    AI for AI
  • 原文地址:https://www.cnblogs.com/hiraeth/p/9026396.html
Copyright © 2011-2022 走看看