在静态函数中获取静态 class 的属性?
Getting properites of static class in static function?
我只想在未实例化的 class 中使用 return class 属性。没有办法实例化这个class?请告诉我...!
我的例子如下↓↓
<?php
class MyTest {
public static $test1 = 'a';
public static $test2 = 'b';
public static function getProperties() {
//how to code here...?
}
}
//plz return $test1, $test2
MyTest::getProperties();
使用self::
访问静态属性:
public static function getProperties() {
return [self::$test1, self::$test2];
}
我只想在未实例化的 class 中使用 return class 属性。没有办法实例化这个class?请告诉我...! 我的例子如下↓↓
<?php
class MyTest {
public static $test1 = 'a';
public static $test2 = 'b';
public static function getProperties() {
//how to code here...?
}
}
//plz return $test1, $test2
MyTest::getProperties();
使用self::
访问静态属性:
public static function getProperties() {
return [self::$test1, self::$test2];
}