首页/Home PHP Basics Static Method Does Not Work In Double Quotes

Static Method Does Not Work In Double Quotes

PrintE-mail
Thursday, 03 April 2008 07:26  

Methods declared as 'static' won't work in double quotes. That is, you can not use MyClass::MyStaticMethod() in double quotes, nor can you use variable's variable. This article will give you some illustrations.

Take this class for example:

class MyClass
{
    static function blah() {
        return 'bbbbllllaaaahhhh';
    }
}

The following code won't work:

echo "Hi MyClass::blah() \n";

Nor will this one:

$cls  = 'MyClass';
$mthd = 'blah()';
$eco = $cls . '::' . $mthd;
echo "Hi  $$eco \n";

This case, you should use concatenation then:

echo 'Hi ' . MyClass::blah() . PHP_EOL; 

Hope that can give you some information.

 

回复

留个脚印儿吧.


回复