Tuesday, July 28, 2009

static methods in php

Static methods can be accessed by self keyword within the class and we can't use this keyword. Let's see the mock zend certification test question.

Question: What is the primary difference between a method declared as static and a normal method?

Answer:

1.Static methods can only be called using the :: syntax and never from an instance
2.Static methods do not provide a reference to $this
3.Static methods cannot be called from within class instances
4.Static methods don't have access to the self keyword
5.There is no functional difference between a static and non-static method
See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide

1 comment:

Anonymous said...

2 is the correct one. 1 is not correct, because you still can access static function from an instance (even with $this), it will only create a warning, but it still works.