Re: Re: Static functions
| From: | Ernest E Vogelsinger | Date: | Mon, 10 Feb 2003 07:47:26 +0000 |
| Subject: | Re: Re: Static functions | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-135017@lists.php.net to get a copy of this message | ||
At 22:52 09.02.2003, Chris Hayes said:
--------------------[snip]--------------------
>At 22:49 9-2-2003, you wrote:
>>yes, you can call a static method on a class by specifying the class name,
>>then 2 colons and finally the function name:
>>
>>classname :: functionname([arg,.....])
>>
>>(of course properties can not be accessed by such methods)
>ah ok, cool
--------------------[snip]--------------------
With PHP you can also determine if your class method has been called via an
object instance, or class static, by checking the $this reference:
class foo {
function test() {
if (isset($this) && is_object($this) && get_class($this) == 'foo')
echo 'I am a foo object';
else
echo 'I have been called as a "static" method';
}
}
$foo = new foo();
foo::test();
$foo->test();
--
>O Ernest E. Vogelsinger
(\) ICQ #13394035
^ http://www.vogelsinger.at/