Home  >  Article  >  Backend Development  >  Detailed explanation of examples of how to use static variables in PHP

Detailed explanation of examples of how to use static variables in PHP

墨辰丷
墨辰丷Original
2018-05-30 09:34:321885browse

This article mainly introduces the use of static variables in PHP, and analyzes the steps and specific operation techniques of using static variables in PHP in the form of examples. Friends in need can refer to the following

1. Define static variables

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

2. Static variable assignment

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. Static variable Use

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 the entire content of this article, I hope it will be helpful to everyone's study.


Related recommendations:

How to issue a PHP custom template engine

PHP JQUERY operation JSON example

phpMethod to implement WeChat scan code payment

The above is the detailed content of Detailed explanation of examples of how to use static variables in PHP. For more information, please follow other related articles on the PHP Chinese website!

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