doukuang1950 2018-10-12 09:22
浏览 41
已采纳

在静态函数php中赋值

I would reuse a variable $spider_flag inside static function to include in other static function. How to do that ?

TK

 public static function start() {

 $spider_flag = false;

          if (!empty($user_agent) || strpos ($user_agent, "Googlebot") > 0) {
            $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);

            if (!empty($user_agent)) {
              foreach (file(Sites/Assets/spiders.txt') as $spider) {
                if (!empty($spider)) {
                  if (strpos($user_agent, $spider) !== false) {
                    $wo_full_name = $spider;
                    $spider_flag = true;

                    break;
                  }
                }
              }
            }
          }

the other function

 public static function getResultSpiderFlag() {
      $spider_flag= ????
      return $spider_flag;

    }
  • 写回答

1条回答 默认 最新

  • dsxgby126001 2018-10-12 09:25
    关注

    below class definition:

    public static $spider_flag;
    

    inside function

    self::$spider_flag = 'something'
    

    or

    self::$spider_flag //for the value;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?