Hiroki Takekuma
Hiroki Takekuma

Reputation: 23

Getting properites of static class in static function?

I just wanna get return class properties in not instantiated class use. There is no way to instance this class? Please tell me...! My example is below↓↓

  <?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();

Upvotes: 1

Views: 17

Answers (1)

Kien Nguyen
Kien Nguyen

Reputation: 2691

Use self:: to access static properties:

public static function getProperties() {
    return [self::$test1, self::$test2];
}

Upvotes: 1

Related Questions