Example analysis of how to use static variables in PHP

黄舟
Release: 2023-03-06 06:12:01
Original
1415 people have browsed it

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;
Copy after login



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');
}
Copy after login



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;
}
Copy after login


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 (m.sbmmt.com)!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!