平平博客平平博客

平平

ping@setbug.com

平平网络setbug.com

文章数
31817
评论数
3056
浏览数
9966397
平平
ping@setbug.com
平平网络setbug.com

php注解实现函数自动执行

代码片段2020-06-19 2936  0 
摘要:介绍让php采用java注解方式实现函数自动执行案例!代码//自动加载类classauto...

介绍

让php采用java注解方式实现函数自动执行案例!

代码

//自动加载类
class autoLoad(){
function __construct(){
  $fileList=[
     "function/function.php";
  ];
  foreach($fileList as $va){
    $annotation=(new annotation())->getAllFunctionAnnotationInFile($va,'autoLoad');
    if(empty($annotation)) return;
    foreach($annotation as $fu => $lo){
      if($lo['autoLoad'][0]){
        call_user_func($fu);
      }
    }
  }
}
}

//函数文件function/function.php

/**
*@autoLoad 'true'
*/
function autoLoad(){
  include 'init.php';
}

/**
*@autoLoad 'true'
*/
function isMyDomain(){
  if(!isMine) exit('恶意域名');
}


//测试文件
new autoLoad();

继续阅读
标签:注解annotation注释autoload自动加载方法函数自动执行
写代码真的很累!麻烦点个赞,评论一下,然后分享给自己的小伙伴!
打赏
海报分享
发表评论
表情
快捷
私密

右滑验证