Can we do this in other OO programming languages? … I misunderstood about static method?
<?php
class A {
public static function func1() {
return "ABC";
}
}
$a = new A;
print $a->func1() . "\n";
?>
Technically, you can do it. Conceptually also yes. A “class” is just another another “object” so it can have methods. But why you want to do it, i.e., why should “func1()” be a class method is a design issue.
“static method” is merely a mean to accomplish implementing “class method” (method that the class itself is a receiver) for some languages.
ความเห็น โดย rawitat pulam — พฤศจิกายน 26, 2011 @ 11:37 pm
This is not what I want to do.
ความเห็น โดย वीर — พฤศจิกายน 27, 2011 @ 12:26 am
Looking at it again, it seems I misunderstood the original question a big bit, sorry about that.
So now, the answer becomes: Most language will allow you to access class methods through “class of instance”. Like, self.class.classMethodName something like this.
Some languages allow you to access them directly through instance though. Like C++ for example
ความเห็น โดย rawitat pulam — พฤศจิกายน 27, 2011 @ 12:19 am
Thank you.
ความเห็น โดย वीर — พฤศจิกายน 27, 2011 @ 12:28 am