Home >Backend Development >PHP Tutorial >Example analysis of how to use static variables in PHP
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)!