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
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED


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?
parent::constructor();


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?
Sort()
arsort()
asort()
ksort()
natsort()
natcasesort()
rsort()
usort()
array_multisort()
uksort().

Question: How can we get the browser properties using PHP?
$_SERVER['HTTP_USER_AGENT']


Question: How can I configure PHP to show error at runtime?
error_reporting(E_ALL) 



Question: How do I turn off PHP Notices?
Add following code in top of php script.
error_reporting(0);


Question: What is T_PAAMAYIM_NEKUDOTAYIM?
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;



Friday, 15 January 2016

Zend Soap Client and Server

Zend Soap Client and Server

Question: What is Zend\Soap\Client?
It is component which is used to send SOAP request messages to a Web service and to receive SOAP response messages from that Web service. Zend\Soap\Client takes two parameter $wsdl, $options.
$wsdl- the URI of a WSDL file.


Question: What options are available in Zend\Soap\Client?
  1. soap_version
  2. classmap
  3. encoding
  4. wsdl
  5. uri
  6. location
  7. style
  8. use
  9. login
  10. proxy credentials like proxy_host, proxy_port, proxy_login and proxy_password
  11. local_cert
  12. compression



Question: How to call Zend\Soap\Client? Give an Example?
$client = new Zend\Soap\Client("MySoapService.wsdl");
$result1 = $client->soapMethod(10);


Question: What is Zend\Soap\Server?
Zend\Soap\Server component works in the WSDL mode, it uses WSDL document to define server object behavior and transport layer.


Question: How to call Zend\Soap\Server for Non-WSDL Mode?
For WSDL Mode
$server = new Zend\Soap\Server('MySoapService.wsdl', $options);

For Non-WSDL Mode
$server = new Zend\Soap\Server(null, $options);



Question: Where is Zend_Rest in ZF2?
Zend_Rest component is removed from zf2. Now, If you want to call rest api, you can use Zend\Http\Client