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;