Sr. PHP Programmer Interview Preparation Guide
Download PDF

Sr. PHP Programmer based Frequently Asked Questions by expert members with experience as Senior PHP Programmer. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts

202 Senior PHP Programmer Questions and Answers:

1 :: Explain What is PHP?

PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning

2 :: Explain what are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

☛ Mysql_fetch_array Fetch a result row as an associative array, a numeric array, or both.

☛ mysql_fetch_object ( resource result ) Returns an object with properties that correspond to the fetched row and moves the internal data pointer ahead. Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows

☛ mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

3 :: What is MVC in PHP context?

Most programmers know this, but interviewers will likely look for a deep understanding of MVC, and some explanation or examples on how/why/ when you used it.

MVC- Model, View, Controller - is simply a way of organizing your code into 3 separate layers each with there own job.

☛ Model - Usually contains data access code and all of you business logic code.
☛ View - Contains markup/design code, generally html,xml, json.
☛ Controller - Usually contains very little code, just whatever is needed to call the Model code and render the View code.

4 :: What are some magic methods in PHP, how might you use them?

Magic methods are basically triggers that occur when particular events happen in your coding. __GET, __SET are magic methods that are called (behind the seen) when you get or set a class property.

5 :: Can the value of a constant change during the script's execution?

No, the value of a constant cannot be changed once it's declared during the PHP execution.

6 :: What are PSRs? Choose 1 and briefly describe it?

PSRs are PHP Standards Recommendations that aim at standardizing common aspects of PHP Development.

An example of a PSR is PSR-2, which is a coding style guide.

7 :: Explain the different types of errors in PHP?

Notices, Warnings and Fatal errors are the types of errors in PHP

☛ Notices:
Notices represents non-critical errors, i.e. accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all but whenever required, you can change this default behavior.

☛ Warnings:
Warnings are more serious errors but they do not result in script termination. i.e calling include() a file which does not exist. By default, these errors are displayed to the user.

☛ Fatal errors:
Fatal errors are critical errors i.e. calling a non-existent function or class. These errors cause the immediate termination of the script.

8 :: Explain the purpose of output buffering in PHP?

Output buffering in PHP buffers a scripts output. This buffer can be edited before returning it to the client. Without output buffering, PHP sends data to the web server as soon as it is ready. Output buffering "send" cookies at any point in the script. Cookies do not have to be necessarily sent near the start of page. Output buffers are stackable and hence sending to output is by choice.

9 :: What is the use of "echo" in php?

It is used to print a data in the webpage, Example: <?php echo 'Global Guideline'; ?> , The following code print the text in the webpage

10 :: What is use of count() function in php?

count() is used to count all elements in an array, or something in an object

11 :: How to select a database?


12 :: What is the use of mysql_real_escape_string() function?

It is used to escapes special characters in a string for use in an SQL statement

13 :: How to find the length of a string?

strlen() function used to find the length of a string

14 :: How do you define a constant?

Using define() directive, like define ("MYCONSTANT",150)

15 :: What are the encryption techniques in PHP?

MD5 PHP implements the MD5 hash algorithm using the md5 function,
eg : $encrypted_text = md5 ($msg);

mcrypt_encrypt :- string mcrypt_encrypt ( string $cipher , string $key , string $data , string $mode [, string $iv ] );
Encrypts plaintext with given parameters

16 :: How to find the position of the first occurrence of a substring in a string?

strpos() is used to find the position of the first occurrence of a substring in a string

17 :: In PHP what is the difference between a Class and an Interface?

Interfaces do not contain business logic, only method signatures that define a template that any classes implementing the interface must contain. Lets take an auto mobile for example. If we were to create and interface for a car we would want to define a few methods like drive, stop, turn left , turn right. This mean that any vehicle that is a car (aka implements the interface car) must have methods for these things, If they do not PHP will throw an error. So if your car is an BMW , Honda or Ford it must be able to stop. How it stops is up to each car (or PHP class) but it must be able to stop. Technically we can decide not to use an interface for cars, but then some types of cars are not forced to have a "stop" method.

18 :: How do you load classes in PHP?

They are trying to gauge your understanding of how class auto loading works. Review the "autoload" and "spl_autoload_register" function (note:you should use the later). The autoload function basically triggers a function when a class is instantiated, you can put whatever logic you like in it but generally you want to include the class file based on some sort of naming convention.

19 :: What is the difference between $var and $$var in PHP?

$$var sets the value of $var as a variable.

$$day='first day of week';
echo $monday; //outputs 'first day of week'

20 :: How can we get the IP address of the client?

This question might show an interview how playful and creative the candidate is because there are many options. $_SERVER["REMOTE_ADDR"]; is the easiest solution, but you can write x line scripts for this question.