Friends

PHP Interview Questions

1. How to get Browser information ?
Using get_browser() we can get the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file. 

echo $_SERVER['HTTP_USER_AGENT'] . "
\n";
$browser = get_browser();
foreach ($browser as $name => $value) {
echo "$name $value 
\n";
}



2. what is final class?
The class which is mentioned as a "final", can not be inherited. So it's methods can not be overridden.
An abstract class can not be a final class as it needs to be extendable.


3. What is abstract class?
Abstract class is a class which can not be instantiated,contains only abstract methods - only method declarations not definitions. Child class must override the methods which are declared as abstract in parent class. These methods must be defined with same (or less restricted) visibility. Also signature should match.



Following is one of the best examples to explain the use of an abstract class and the behavior of it.
01class Fruit {
02private $color;
03
04public function eat() {
05 //chew
06}
07
08 public function setColor($c) {
09  $this->color = $c;
10 }
11}
12
13class Apple extends Fruit {
14 public function eat() {
15  //chew until core
16 }
17}
18
19class Orange extends Fruit {
20 public function eat() {
21  //peel
22  //chew
23 }
24
}
Now taste an apple
1$apple new Apple();
2$apple->eat();

What’s the taste of it? Obviously it’s apple

Now eat a fruit

1$fruit new Fruit();
2$fruit->eat();

What’s the taste of it? It doesn’t make any sense. does it? Which means the class fruit should not be Instantiable . This is where the abstract class comes into play

1abstract class Fruit {
2 private $color;
3
4 abstract public function eat()
5
6 public function setColor($c) {
7  $this->color = $c;
8 }
9}



4. OverView of Drupal CMS 

Basically, there are 5 main layers in Drupal where information flows,

  1. Data (Node, ETC)
  2. Modules
  3. Blocks and Menus
  4. User Permissions
  5. Template

Data - Base of the system is collection of Nodes. – the data pool

Modules -These are functional plugins that are either part of the Drupal core (they ship with Drupal) or they are contributed items that have been created by members of the Drupal community.

Blocks and Menus - This is the next layer where we find blocks and menus. Blocks often provide the output from a module or can be created to display whatever you want, and then can be placed in various spots in your template (theme) layout. Blocks can be configured to output in various ways, as well as only showing on certain defined pages, or only for certain defined users.

User Permissions - Here is the next layer where settings are configured to determine what different kinds of users are allow to work and see.

Template - This is mainly the site theme or the skin. This is made up predominantly of XHTML and CSS, with some PHP variables intermixed.

5. What are the two new error levels introduced in PHP5.3?

E_DEPRECATED - The E_DEPRECATED error level is used to indicate that a function or feature has been deprecated.

E_USER_DEPRECATED - The E_USER_DEPRECATED level is intended for indicating deprecated features in user code, similarly to the E_USER_ERROR and E_USER_WARNING levels.

5. Explain Late Static binding.


01class A {
02    public function who() {
03        echo __CLASS__;
04    }
05    public function test() {
06        $this->who();
07    }
08}
09
10class extends A {
11    public function who() {
12        echo __CLASS__;
13    }
14}
15$obj new B;
16$obj->test();
Out put of the above snippet is? B This is mainly because we have the object instance named as $this is for the class B, though the function is instantiated inside class A. But, If you need the expected output which is “A”, we can call them statically as follows
01class A {
02    public static function who() {
03        echo __CLASS__;
04    }
05    public static function test() {
06        self::who();
07    }
08}
09
10class extends A {
11    public static function who() {
12        echo __CLASS__;
13    }
14}
15
16B::test();
Out put -> A
Main limitation of self:: or __CLASS__ are resolved using the class in which the function belongs, as in where it was defined. By introducing late static binding this limitation has been resolved as follows,
01class A {
02    public static function who() {
03        echo __CLASS__;
04    }
05    public static function test() {
06        static::who(); // Here comes Late Static Bindings
07    }
08}
09
10class extends A {
11    public static function who() {
12        echo __CLASS__;
13    }
14}
15
16B::test();
Out put -> B


Twitter Delicious Facebook Digg Stumbleupon Favorites More