溫馨提示×

php self如何調用靜態屬性

PHP
小樊
92
2024-07-13 01:52:26
欄目: 編程語言

在PHP中,可以使用self::關鍵字來調用靜態屬性。例如:

class Example {
    public static $staticProperty = "Static Property";

    public function getStaticProperty() {
        return self::$staticProperty;
    }
}

echo Example::$staticProperty; // 輸出 "Static Property"

$example = new Example();
echo $example->getStaticProperty(); // 輸出 "Static Property"

在上面的示例中,我們使用self::$staticProperty來調用靜態屬性$staticProperty。無論是在類的內部還是外部,都可以使用self::關鍵字來訪問靜態屬性。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女