Saturday, 16 January 2016

Advanced PHP Interview Questions and Answers

Advanced PHP Interview Questions and Answers

Question: What is PEAR in php?
PEAR means PHP Extension and Application Repository.
PEAR is a framework and distribution system for reusable PHP components. PEAR can be installed by bringing an automated wizard.
Following are main purpose of PEAR
A structured opensource library .
Distribution and package maintenance.
The PHP Foundation Classes (PFC)
The PHP Extension Community Library (PECL)

Question: How can we repair a MySQL table?
We can repair the MySQL with following 3 queries. Each have its own feature.
REPAIR TABLE tablename

Question: What Is a Persistent Cookie?
A persistent cookie is a cookie which is stored in a cookie file permanently on the browser.
A persistent cookie can be used for tracking long-term information.
Persistent cookies are less secure.

Question: How to create persistent cookie in php?
Cookies will only persistent for as long as you have set them.
setcookie( "cookieName", 'cookieValue', strtotime( '+1 year' ) ); //set for 1 year

Question: What is meant by urlencode and urldecode?
urlencode() returns the URL encoded version of the given string.
It convert special characters into % signs followed by two hex digits.

urldecode() returns the Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.

Question: How To Get the Uploaded File Information in PHP Global variables?
We are all data in $_FILES variable and are following
$_FILES[$fieldName]['name'] - The Original file name on the browser system.
$_FILES[$fieldName]['type'] – The file type determined by the browser.
$_FILES[$fieldName]['size'] – The Number of bytes of the file content.
$_FILES[$fieldName]['tmp_name'] – The temporary filename of the file in which the uploaded file was stored on the server.
$_FILES[$fieldName]['error'] – The error code associated with this file upload.

Question: How can I execute a PHP script using command line?
php c:/wamp/www/myfile.php

Question: Are objects passed by value OR by reference?
Everything is passed by value.

Question: How do you call a constructor of a parent class from child class?

Question: Can we use include ("abc.php") two or more times?
Yes, we can include mutiple times.

Question: What is the difference between the functions unlink and unset?
unlink() deletes the given file from the file system.
unset() makes a variable undefined from memory

Question: What are the different functions in sorting an array?

Question: How can we get the browser properties using PHP?

Question: How can I configure PHP to show error at runtime?

Question: How do I turn off PHP Notices?
Add following code in top of php script.

T_PAAMAYIM_NEKUDOTAYIM the scope resolution operator (double colon)

Qustion: What is output of following program?
function doSomething( &$arg )
    $return = $arg;
    $arg += 1;
    return $return;

$a = 3;
$b = doSomething( $a );

echo $a;
echo '\n';
echo $b;

Question: How to protect your website from SQL injection attack?
use mysql_real_escape_string() function.

Question: How to protect your website from CSRF (Cross-Site Request Forgery) attack?
Add a token on every important request to secure important operations

Question: How to protech your website from XSS (Cross-Site Scripting) attack?
use php function htmlentities()

Question: what is the list of sensible functions?
exec(), passthru(), system(), popen(), eval(), preg_replace() 

Question: What is output of following?
$a = 012;
echo $a / 4;


Anonymous said...

Question: What is full form of URL, URI and URN?
URL - Uniform Resource Locator

URI - Uniform Resource Indicator

URN - Uniform Resource Name

Am I correct?

Yogi said...

Good Attempt

TrakCheap said...


ApertureZ said...

Good set of questions

Aiswarya T S said...

Thank you

Ankur Garg said...

nice tutorial.

Suresh Kardam said...

$a = 012;
echo $a / 4;

Why $a =10 and output is 2.5 ?

Unknown said...

012 is consider as octal base in php.

so, 1*8power1 + 2*8power0 = 8 + 2 = 10

Ashraf said...

Good set of questions

Yogesh Rathod said...

nice tutorial

ram ramky said...

Nice post! definitively I will come back to update me on this technology Thanks for the informative post. Keep doing.
Software Testing courses in chennai
software testing course in chennai

Sakthi Murugan said...

I feel happy to find your post, excellent way of writing and also I would like to share with my colleagues so that they also get the opportunity to read such an informative blog.
French Class in Chennai
French Training
French Training in Chennai

Post a Comment