在静态函数php

时间:2018-10-12 17:22:37

标签: php

我会在静态函数内重用变量$spider_flag来包含在其他静态函数中。该怎么做?

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;
                  }
                }
              }
            }
          }

其他功能

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

    }

1 个答案:

答案 0 :(得分:0)

在类定义下面:

public static $spider_flag;

内部功能

self::$spider_flag = 'something'

self::$spider_flag //for the value;