zoukankan      html  css  js  c++  java
  • 魔术方法__call

    //先讲解__call方法的基础使用

    //
    __call魔术方法,当调用一个类的方法,此方法不存在 //就会执行__call方法 class Computer { public function _run() { echo '运行'; } //采用__call()方法屏蔽调用 //__call()里面有两个参数 //第一个参数为调用的那个方法名 //第二个参数为方法中传入的值 public function __call($_methodName,$_argList) { echo $_methodName.'()not exist'; //print_r($_argList); } } $computer = new Computer(); //如果quiet()方法不存在,执行__call()方法 $computer->quiet(); //------------------ class MethodTest { public function __call($name, $arguments) { // 注意: $name 的值区分大小写 echo "Calling object method '$name' " . implode(', ', $arguments). "\n"; } /** PHP 5.3.0之后版本 */ public static function __callStatic($name, $arguments) { // 注意: $name 的值区分大小写 echo "Calling static method '$name' " . implode(', ', $arguments). "\n"; } } $obj = new MethodTest; $obj->runTest('in object context'); MethodTest::runTest('in static context'); // PHP 5.3.0之后版本 //以上例程会输出: //Calling object method 'runTest' in object context //Calling static method 'runTest' in static context
  • 相关阅读:
    全排列(next_permutation)
    Codeforces Round #321 (Div. 2)C(tree dfs)
    cf_ducational Codeforces Round 16_D(gcd)
    cf455a(简单dp)
    cf584a(水题)
    cf112a(水题)
    冒泡排序
    Python内置类型性能分析
    常见时间复杂度
    MongoDB 备份
  • 原文地址:https://www.cnblogs.com/loveyouyou616/p/2806632.html
Copyright © 2011-2022 走看看