문제

Is it possible to do something like self:: in PHP to not need to specify the class-name tro call a static method within the same class. See how I do it:

public class Foo
 public static void blaa() {...}
 public void foobar
 {
    Foo.blaa();
 }

but I'd like to it like

public class Foo
 public static void blaa() {...}
 public void foobar
 {
    _SOME_SORT_OF_SELF_.blaa();
 }

to not have to write down the classname over and over again... same would go for static attributes. Instead of using Foo.MY_ATTR maybe accessing it via _SOME_SORT_OF_SELF_.MY_ATTR.

Possible? Thanks

도움이 되었습니까?

해결책

If you're trying to call a static method within the class it's defined in, you don't need to specify the type. (The rules get a little more complicated with nested classes).

For instance methods and variables, you can use the this keyword in your field access and method invocation expressions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top