Home >Backend Development >PHP Tutorial >Example analysis of how to use static variables in PHP

Example analysis of how to use static variables in PHP

黄舟
黄舟Original
2017-02-24 09:30:581468browse

The examples in this article describe the use of static variables in PHP. Share it with everyone for your reference, the details are as follows:

1. Define static variables

public static $endpoint,$accessKeyId,$accessKeySecret,$bucket;



2. Assign static variables

protected function _initialize() {
  self::$endpoint = C('OSS_ENDPOINT');
  self::$accessKeyId = C('OSS_ACCESS_ID');
  self::$accessKeySecret = C('OSS_ACCESS_KEY');
  self::$bucket = C('OSS_TEST_BUCKET');
}



3. Use of static variables

public static function getOssClient()
{
  try {
   $ossClient = new OssClient(self::$accessKeyId, self::$accessKeySecret, self::$endpoint, false);
  } catch (OssException $e) {
   printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
   printf($e->getMessage() . "\n");
   return null;
  }
  return $ossClient;
}


The above is how to use static variables in PHP Example analysis content, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn