本文實例敘述了PHP中靜態變數的使用方法。分享給大家供大家參考,具體如下:
1.定義靜態變數
public static $endpoint,$accessKeyId,$accessKeySecret,$bucket;
2.靜態變數賦值
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.靜態變數使用
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; }
以上是PHP中靜態變數的使用方法實例分析 的內容,更多相關內容請關注PHP中文網(m.sbmmt.com)!