ReflectionClass::getStaticPropertyValue()函數是PHP中的內置函數,用於返回靜態屬性的值。
用法:
mixed ReflectionClass::getStaticPropertyValue( string $name, mixed &$def_value )
參數:此函數接受單個參數名稱,該名稱是指定靜態屬性的名稱。
返回值:此函數返回靜態屬性的值。
以下示例程序旨在說明PHP中的ReflectionClass::getStaticPropertyValue()函數:
示例1:
<?php
// Defining a class named as Departments
class Departments {
static $Dept1 = 'CSE';
private static $Dept2 = 'ECE';
public static $Dept3 = 'EE';
}
// Using ReflectionClass over the class Departments
$ReflectionClass = new ReflectionClass('Departments');
// Calling getStaticPropertyValue() function
$A = $ReflectionClass->getStaticPropertyValue('Dept3');
// Getting the value of the static property.
var_dump($A);
?>
輸出:
string(2) "EE"
示例2:
<?php
// Defining a class named as Departments
class Departments {
static $Dept1 = 'CSE';
static $Dept2 = 'ECE';
public static $Dept3 = 'EE';
}
// Using ReflectionClass over the class Departments
$ReflectionClass = new ReflectionClass('Departments');
// Calling getStaticPropertyValue() functions
$A = $ReflectionClass->getStaticPropertyValue('Dept1');
$B = $ReflectionClass->getStaticPropertyValue('Dept2');
$C = $ReflectionClass->getStaticPropertyValue('Dept3');
// Getting the value of the static property.
var_dump($A);
var_dump($B);
var_dump($C);
?>
輸出:
string(3) "CSE" string(3) "ECE" string(2) "EE"
參考: https://www.php.net/manual/en/reflectionclass.getstaticpropertyvalue.php
相關用法
- PHP ReflectionClass isUserDefined()用法及代碼示例
- PHP ReflectionClass getProperty()用法及代碼示例
- PHP ReflectionClass isIterateable()用法及代碼示例
- PHP ReflectionClass getProperties()用法及代碼示例
- PHP ReflectionClass getInterfaceNames()用法及代碼示例
- PHP ReflectionClass isTrait()用法及代碼示例
- PHP ReflectionClass getDefaultProperties()用法及代碼示例
- PHP ReflectionClass isSubclassOf()用法及代碼示例
- PHP ReflectionClass hasConstant()用法及代碼示例
- PHP ReflectionClass getMethod()用法及代碼示例
- PHP ReflectionClass isAbstract()用法及代碼示例
- PHP ReflectionClass isAnonymous()用法及代碼示例
- PHP ReflectionClass getStartLine()用法及代碼示例
- PHP ReflectionClass implementsInterface()用法及代碼示例
- PHP ReflectionClass hasMethod()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | ReflectionClass getStaticPropertyValue() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。