Friday, 22 May 2015

PHP interview questions and answers for 5 year experienced

PHP interview questions and answers for 5 year experienced

Question: How array_walk function works in PHP?
Purpose: It is used to update the elements/index of original array.
How: in array_walk, two parameter are required.
1st: original array
2nd: An callback function, with use of we update the array.

Question: Difference Between Zend framework 2 VS Zend framework 1?

Question: How to achieve Multilevel inheritance in PHP?
//base class
class grandParent{}

//parent class extend the base class
class parent extends grandParent{}

//chid class extend the parent class
class child extends parent{}

Question: What is Routing? How it works in Zend?
Routing is the process of taking a URI endpoint and decomposing it into parameters to determine which module, controller and action to that controller should receive the request.
This values of the module, controller, action and parameters are packaged into a Zend_Controller_Request_Http object which is then processed by Zend_Controller_Dispatcher_Standard.

Question: What is Zend_Controller_Front?
Front Controller is design pattern.
Zend framework use the Zend_Controller_Front which is based on Front controller design pattern. Zend_Controller_Front purpose is to initialize the request environment, route the incoming request and then dispatch any discovered actions.
It aggregates any responses and returns them when the process is complete.

Question: What is difference between TDD and BDD?
TDD is Test-driven development
BDD is Behaviour-driven development

Question: What is Zend_Translate? Where it is used?
It is component of Zend Framework. Responsible for converting the text data from one language to another languages.
It is used in multilingual website where we are showing content display in multilingual.

Question: What are different Adapter of zend_translate?
Following are main Adapter of zend translator

Question: How to get 2nd highest salary of employee, if two employee may have same salary?
select salary from employee group by salary order by salary limit 1,1

Question:How to find duplicate email records in users table?
SELECT u1.first_name, u1.last_name, u1.email FROM users as u1
    SELECT email FROM users GROUP BY email HAVING count(id) > 1
    ) u2 ON u1.email = u2.email;

Question: How to pass data in header while using CURL?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'headerKey: HeaderValue ',
  'Content-Type: application/json',
  "HTTP_X_FORWARDED_FOR: xxx.xxx.x.xx"
echo curl_exec($ch);

Question: How to pass JSON Data in CURL?
$jsonData='{"name":"Web Technology Experts","email":"[email protected]"}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);

Question: What is Final Keyword in PHP?
PHP introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final keyword.

Question: What are Properties of Object Oriented Systems?
Encapsulation of data
Extensibility of existing data types and classes
Support for complex data types

Question: How can we prevent SQL-injection in PHP? Sanitize the user data before Storing in database.
While displaying the data in browser Convert all applicable characters to HTML entities using htmlentities functions.

Question: How to redirect https to http URL and vice versa in .htaccess?
Redirect https to http
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Redirect http to https
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Question: What are benefits of htaccess?
We can do following benefits stuff with htaccess.
Routing the URL
Mange Error Pages for Better SEO
Redirection pages
Detect OS (like Mobile/Laptop/Ios/Android etc)
Set PHP Config variable
Set Environment variable
Allow/Deny visitors by IP Address
Password protection for File/Directory
Optimize Performance of website
Improve Site Security

Question: What is Reference Transaction in Paypal?
In Reference transaction,
With use of first transaction done by customer, we can do mutiple transaction without need another approvel.
In this, we store the transaction_id(First transaction), and use this transaction_id as reference_id for net payments.

It has two methods.
1) DoDirect payment. (Accept the credit card by website)
2) Express Checkout. (website doesn't accept credit card in own website, customer pay on paypal.com)
Click to Know More

Question: Difference between Apache and Nginx?
Nginx is based on event-driven architecture.
Apache is based on process-driven architecture.

Nginx development started only in 2002.
Apache initial release was in 1995.

Nginx doesn't create a new process for a new request.
Apache creates a new process for each request.

In Nginx, memory consumption is very low for serving static pages.
Apache’s nature of creating new process for each request, that's why it  increases the memory consumption.

Nginx is extremely fast for serving static pages as compare to Apache.

In complex configurations apache can be configured easily as compare to Nginx.

Apache has excellent documentation as compare to Nginx.

Nginx does not support Operating Systems like OpenVMS and IBMi where as Apache supports much wider range of Operating Systems.

The performance and scalability of Nginx is not completely dependent on hardware resources.
The Performance and scalability of the Apache is dependent on underlying hardware resources like memory and CPU.

1 comment:

  1. Nice questions. Please add Laravel & Phalcon related questions as well.