Sunteți pe pagina 1din 9

y

What is the use of Final class and can a final class be an abstract?
The Final keyword is used to make the class uninheritable. So the class or its methods can not be overridden.
1 final class Class1 { 2 // ... 3} 4 5 class FatalClass extends Class1 { 6 // ... 7} 8 9 $out= new FatalClass();

An Abstract class will never be a final class as an abstract class must be extendable.
y

Explain abstract class and its behaviour?


Abstract class is defined as a solitary entity, so other classes can inherit from it. An abstract class can not be instantiated, only the subclasses of it can have instances. Following is one of the best examples to explain the use of an abstract class and the behavior of it.
01 class Fruit { 02 private $color; 03 04 public function eat() { 05 //chew 06 } 07 08 public function setColor($c) { 09 $this->color = $c; 10 } 11 } 12 13 class Apple extends Fruit { 14 public function eat() { 15 //chew until core 16 } 17 } 18 19 class Orange extends Fruit { 20 public function eat() { 21 22 //peel //chew

23 } 24 }

Now taste an apple


1 $apple = new Apple(); 2 $apple->eat();

Whats the taste of it? Obviously its apple Now eat a fruit
1 $fruit = new Fruit(); 2 $fruit->eat();

Whats the taste of it? It doesnt make any sense. does it? Which means the class fruit should not be Instantiable . This is where the abstract class comes into play
1 abstract class Fruit { 2 private $color; 3 4 abstract public function eat() 5 6 public function setColor($c) { 7 $this->color = $c; 8 } 9}

Write a small function to calculate n to the power of n?


In the above question the interviewer is expecting the logic behind the scene (Recursive). Actually he may directly ask you to write a recursive function to calculate N to the power of N, or given number to the power of N. Following is the simplest way that you can write a PHP recursive function for this functionality.
1 function MyPow($r, $w){ 2 if($w==0) 3 return 1; 4 else 5 return MyPow($r, $w-1) * $r; 6} 7 8 echo MyPow(10, 2);

Also this functionality substitutes by the pow() function in PHP.


y

Explain drupal flow of information among 5 main layers


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

1. 2. 3. 4. 5.

Data (Node, ETC) Modules Blocks and Menus User Permissions 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
Understanding this flow of information is very important if you are facing A Drupal project targeted interview as the interviewer might test your overall knowledge of Drupal CMS by asking this sort of questions.
y

Mention two useful shorcut functions available globally in cake php


Following are 2 main shortcut functions available in cakephp

1 // similar to print_r(), but dumps to the view and 2 // is disabled if debug isn't > 0 in config.php 3 pr($anything); 4 5 // returns the correctly internationalized plural or 6 // singular depending on locale. 7 __n($singular, $plural, $count, $return);
If you are working with CakePHP and havent figure it out yet, its worth looking through basics.php in the API docs.

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.

y Late static binding php5


01 class A { 02 public function who() { 03 04 05 06 07 echo __CLASS__; } public function test() { $this->who(); }

08 } 09 10 class B extends A { 11 12 13 14 } public function who() { echo __CLASS__; }

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
01 class A { 02 public static function who() { 03 04 05 06 07 08 } 09 10 class B extends A { 11 12 13 14 } 15 16 B::test(); public static function who() { echo __CLASS__; } echo __CLASS__; } public static function test() { self::who(); }

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,
01 class A { 02 public static function who() { 03 04 05 06 07 08 } 09 10 class B extends A { echo __CLASS__; } public static function test() { static::who(); // Here comes Late Static Bindings }

11 12 13 14 } 15

public static function who() { echo __CLASS__; }

16 B::test();

Out put -> B

y back to the basics


This is just a quick note about how you must prepare for your technical interview whether its a face to face or a written. Before you prepare for a technical interview you must re-work on your basics in the first place. if you are not sure enough dont go to the interview. Prepare well for your next interview. It will help you a lot For an instance at least work on following aspects, y Client Server > What is client server architecture? Basic requesting methods to the server? y Sessions -> What is a session? Where sessions are stored? How session reference is carried in the browser(client) side? y OOP -> What is a class? what is overloading? what is overriding and how you do these with examples? y XML -> What is xml? and whats the use of it? y AJAX -> What is ajax? if you use 3rd party tool at least know the basic functions. y Frameworks > Design patterns used? MVC? Explain cakephp, zend etc y CMS-> At least the knowledge of integrating a template. Joomla, Drupal, Magento
y

sessions and cookies


Face to face technical interviews, questions related to sessions and cookies will pop up regularly. Since most of the developers are familiar with these sort of basic php questions they tend to ask more tricky questions, but if you have the correct idea then it is easy to answer any of those tricky questions. Lets have a look on potential questions, Where is the sessions are stored? Sessions are stored in server side and it is accessed by a unique id which is known as the session-id where each user/visitor is assigned when they access your website. How the session-id is propagated within your website? Basically, there are 2 methods either store it in a cookie or propagated in the URL. Session security questions will not be asked in an entry level interviews but, if an advanced level candidate who has experience in developing robust and secured application must know about the vulnerabilities. Leaking out an existing session-id to a third party is very risky if the session is filled with more important information. Main two methods of vulnerabilities are, - When the session-id is carrying in URLs If an external link from your site, a URL with the id might be stored in the external sites referrer log. - Active attacker might listen to network traffic While the session-id flows over the network and if it is not encrypted an active listener might grab it. The best solution is to implement SSL and make it a must for all the users.

Oral php interview questions


Here is a list of php question areas that might be asked in an add-hoc oral technical interview. First of all they will focus on some more basic questions, - Difference between GET and POST - Echo and print - Language constructors and so on Then most likely they would focus on, - The behaviors of sessions and cookies - Ways of a session ID can be passed - Db connection strings and how can it be centralized and stuff like that. - Difference between normal connection and a persistent connection etc.. Then obviously the interviewer will have to asses on your knowledge in Object Oriented Programming techniques, - Simply what is a class or object? - Some definitions on OOP techniques like, Encapsulation, overloading, inheritance. Also design pattern questions will be asked here. - Which OOP pattern implements a class that must be instantiated only once in a life span of a script? - Some more questions on design patterns mostly real world scenarios. - How design patterns can be used as a mix of more than one pattern? - Some more discussions related to MVC, Abstract factory, and singleton. Last but not least they will focus on your knowledge about the security issues, best practices, probably about register global issues and so on. Then the interviewers will focus on more into your CV and about the Frameworks and CMSs you have been exposed to. We will be discussing all of above points one by one in later posts stay tuned. Cheers !

php security interview questions


Consider the following code snippet. Is this code acceptable from a security standpoint? Assume that the $action and $data variables are designed to be accepted from the user and register_globals is enabled.
01 <?php 02 if(isUserAdmin()) { 03 $isAdmin = true; 04 } 05 $data = validate_and_return_input($data); 06 switch($action){ 07 case 'add': 08 addSomething($data); 09 break; 10 case 'delete': 11 if($isAdmin) { 12 deleteSomething($data); 13 } 14 break; 15 case 'edit':

16 if($isAdmin) { 17 editSomething($data); 18 } 19 break; 20 default: 21 print Bad Action.; 22 } 23 ?>

A. Yes, it is secure. It checks for $isAdmin to be True before executing protected operations B. No, it is not secure because it doesnt make sure $action is valid input C. No, it is not secure because $isAdmin can be hijacked by exploiting register_globals D. Yes, it is secure because it validates the user-data $data E. Both A and B The correct answer is C. This code is, by any means, not secure! In fact, it is the classic security exploit of PHP scripts using the register_globals configuration directive. The problem lies in the $isAdmin variable: although this is clearly a Boolean value, it is only set in the event that the user is an Admin and not set at all if the user is not. Because register_globals is enabled, by simply appending that variable to the end of the URL as a GET parameter, a malicious user could easily impersonate an administrator: http://www.example.com/action.php?action=delete&data=foo&isAdmin=1
y

Blue print of an object


What is the construct used to define the blueprint of an object called? A class is a blueprint of an object, which is an instance of a class.

why cakephp? interview question


In an interview the interviewer asked,

Why we use cakephp? We can just have our own structure and keep developing projects without making things more complicated. Why cake?
The best answer for this question from the cakephp Cookbook is, We dont have to re-invent the wheel. Every time we sit for a new project, we have a more structural way of developing the project with an already installed development environment and we just have to start our rapid application straight a way with the business logic. Some of the key features the framework provides are, - MVC structure - Code generation - CRUD for database interaction - Application scaffolding - Code generation - Built-in validation - Data sanitation - Flexible casching - Localization

and lot more


Our primary goal is to enable you to work in a structured and rapid mannerwithout loss of flexibility by cakephp org. y

MVC structure- cakephp


What is meant by MVC (Model View Controller)?

MODEL VIEW CONTROLLER, is a software architecture, currently considered an architectural pattern used in software engineering. This isolates business logic from presentation logic. 1. The Model represents the application data 2. The View renders a presentation of model data 3. The Controller handles and routes requests made by the client
y

Strings and regular expressions


What will be the answer of the following code snippet?
1 echo 'Testing ' . 1 + 2 . '45';

Simply you will give the answer as : Testing 345 But the answer is : 245 That is because you can not sum a number with a string. The first part, before the plus mark is a string though there is 1 there. So engine will simply get it as 0 and the latter part as 245. so answer will be 245.
y

String Concatenation and regular expressions


Following question were asked in a technical php interview question paper Which of the following will not combine strings $s1 and $s2 into a single string?
$s1 = 'a'; $s2 = 'b'; A. $s1 + $s2 B. "{$s1}{$s2}" C. $s1.$s2 D. implode('', array($s1,$s2)) E. All of the above combine the strings

You can not concatenate 2 string using +. The answer will be 0 ; so here the answer is A.
y

Strings and Regular Expressions


Consider the following script. What line of code should be inserted in the marked location in order to display the string php when this script is executed?
1 $alpha = 'abcdefghijklmnopqrstuvwxyz'; 2 $letters = array(15, 7, 15); 3 foreach($letters as $val) { 4 /* What should be here */ 5}

A. echo chr($val); B. echo asc($val); C. echo substr($alpha, $val, 2); D. echo $alpha{$val}; E. echo $alpha{$val+1} An array can be accessed like this as well. $alpha{$val}

heredoc syntax
heredoc syntax can be used to declare complex strings, What will out put the following code snippet?

1 <?php 2 $who = "questions"; 3 echo <<<TEXT 4 So I said, "php interview $who" 5 TEXT; 6 ?>

Answer So I said, php interview questions In general, the functionality of this heredoc syntax is similar to double quotes.
y y

Taxonomy in Drupal
What is taxonomy in drupal? We can define any number of vocabularies (category types) and terms (categories) e.g. Controversial Content: (vocabulary) violence (term) adult content (term) Genre (Vocabulary) Comedy (term) Romance (term) We can config which content types are compatible with which vocabulary and which nodes are belong to which terms. Some important drupal modules: Views, CCK, Path auto, FCK Editor, User points, Flags, Panels, Image cache

drupal view module


Why View module is so important in drupal? Views can be used to generate lists of content in various formats same as report generator works.

y y

drupal user permission mechanism


What is the user permission mechanism in drupal? We can create roles (moderators, proof readers, content admins etc) and we can permit each task to each role. A user can have 1 or many roles.

What is cakephp
Cakephp is a framework which is used in rapid development. It provides an extensible architecture for developing, maintaining, and deploying applications using MVC (Model View Controller) and ORM(Object Relational Mapping) architectures. Helps developers, in less code and more flexibility.

S-ar putea să vă placă și