Wednesday, 26 July 2017

PHP interview questions and answers for 4 year experience

PHP interview questions and answers for 4 year experience

Question: Difference between include and require?
include: It include a file, It does not find through an warning.
require: It include a file, It does not find through an fatal error, process exit.


Question: How to get IP Address of client?
$_SERVER['REMOTE_ADDR'];



Question: How to get IP Address of Server?
$_SERVER['SERVER_ADDR'];



Question: What is output of following?
$a = '10';
$b = &$a;

$b = "2$b";

echo $a;
echo $b;

Output
210
210



Question: What are the main error types?
  1. Notices: Simple, non-critical errors that are occurred during the script execution.Ideally we should fix all notices.
    echo $undefinedVar;
    
  2. Warning: more important than Notice but it is also non-critical errors that are occurred during the script execution. It should be fixed.
    include "non-ExistFile.php";
    
  3. Error: critical errors due to which script execution stopped. It must be fixed.
    require "non-ExistFile.php";
    



Question: How to enable/disable error reporting?
Enable error
error_reporting(E_ALL);

Disable error
error_reporting(0);



Question: What are Traits?
Traits are a mechanism that allows you to create reusable code in PHP where multiple inheritance is not supported. To create a Traits we use keyword trait.
Example of Traits
trait users {
    function getUserType() { }
    function getUserDescription() {  }
    function getUserDelete() {  }
}

class ezcReflectionMethod extends ReflectionMethod {
    use users;    
}

class ezcReflectionFunction extends ReflectionFunction {
    use users;
}



Question: How to extend a class defined with Final?
No, You can't extend. A class declare with final keyword can't be extend.


Question: What is full form of PSRs?
PHP Standards Recommendations


Question: What is the difference between $message and $$message?
$message is a simple variable whereas $$message is variable whose name is stored in another variable ($message).


Question: How to destroy the session?
session_destroy



Question: How do you execute a PHP script from the command line?
  1. Get the php.exe path from server (My PHP path is : D:\wamp\bin\php\php5.5.12)
  2. In environment variable, Add this path path under PATH variable.
  3. Re-start the computer.
  4. Now, you can execute php files from command file.
    php hello.php



Question: How to repair the session?
REPAIR TABLE tablename 
REPAIR TABLE tablename QUICK 
REPAIR TABLE tablename EXTENDED 



Question: Are Parent constructors called implicitly inside a class constructor?
No, You need to call explicitly.
parent::constructor($value);



Question: What does $_GLOBALS means?
It is associate variable which have all the global data of GET/POST/SESSION/_FILES/ENV/SERVER/GLOBALS etc.
Array
(
    [_GET] => Array
        (
        )

    [_POST] => Array
        (
        )

    [_COOKIE] => Array
        (    
            [_gu] => 1cf7097e-eaf0-486d-aa34-449cf1164ba8
            [_gw] => 2.127103(sc~1,s~oru42c,a~1)127418(sc~1,s~oru42c)u[~0,~0,~0,~0,~0]v[~ev3o1,~4,~0]a()
            [PHPSESSID] => ki18pnad1knttqv5i6233sjem7
        )

    [_FILES] => Array
        (
        )

    [_ENV] => Array
        (
        )

    [_REQUEST] => Array
        (
        )

    [_SERVER] => Array
        (            
            [REQUEST_TIME_FLOAT] => 1501064295.228
            [REQUEST_TIME] => 1501064295
        )

    [GLOBALS] => Array
 *RECURSION*
    [_SESSION] => Array
        (
        )

)



Question: How is it possible to parse a configuration file?
parse_ini_file('config.ini');


Question: What is the difference between characters \034 and \x34? \034 is octal 34 and \x34 is hex 34.


Question: Explain soundex() and metaphone().?
soundex() function calculates the soundex key of a string. A soundex key is a four character long alphanumeric strings that represents English pronunciation of a word.
$str= "hello";
Echo soundex($str);

metaphone() the metaphone() function calculates the metaphone key of a string. A metaphone key represents how a string sounds if pronounced by an English person.


No comments :

Post a Comment