Showing posts with label PHP Interviews Questions. Show all posts
Showing posts with label PHP Interviews Questions. Show all posts

Friday 11 August 2017

PHP Technical Interview Questions and Answer for 3 year experienced

PHP Technical Interview Questions and Answer for 3 year experienced

Question: What is output of below script?
var_dump(0123 == 123);
var_dump('0123' == 123);
var_dump('0123' === 123);

Output
var_dump(0123 == 123);//false
var_dump('0123' == 123); //true
var_dump('0123' === 123);//false



Question: What is output of below script?
var_dump(true and false);
var_dump(true && false);
var_dump(true || false);

Output
var_dump(true and false); //false
var_dump(true && false); //false
var_dump(true || false); //true



Question: What is output of below script?
$a1=true and false;
$a2=true && false;
$a3=true || false;

var_dump($a1);
var_dump($a2);
var_dump($a3);

Output
$a1=true and false;
$a2=true && false;
$a3=true || false;

var_dump($a1);//true
var_dump($a2);//false
var_dump($a3);//true



Question: What is output of below script?
echo  10 + "10%" + "$10";

Output
echo  10 + "10%" + "$10"; //20

Reason: First 10 is 10
Second 10 is 10
Third 10 is 0 (Because start with $)


Question: What is output of below script?
$text = 'HELLO';
$text[1] = '$';
echo $text;

Output
$text = 'HELLO';
$text[1] = '$';
echo $text;//H$LLO 


Question: What is output of below script?
$x = NULL;
var_dump($x);

Output
$x = NULL;
var_dump($x);/null


Question: Why do we use ob_start()?
Ob_start used to active the output buffering .


Question: What is a .htacces file?
.htaccess is a configuration file running on server.
Following task can be done with .htacces?
  1. URL Rewrite
  2. Website password protected.
  3. Restrict ip addresses
  4. PHP/Apache Configuration
  5. Set browser caching for Speed up application.


Question: What is the difference between compiler language and interpreted language?
Interpreted language executes line by line, if there is some error on a line it stops the execution of script. Compiler language can execute the whole script at a time and gives all the errors at a time. It does not stops the execution of script ,if there is some error on some line.


Question: What is type hinting?
Type hinting means the function specifies what type of parameters must be and if it is not of the correct type an error will occur.



Question: What will be output of following?
$x = 5;
echo $x;
echo "
"; echo $x+++$x++; echo "
"; echo $x; echo "
"; echo $x---$x--; echo "
"; echo $x;



Output
5
11
7
1
5


Question: What will be output of following?
$a = 1;
$b = 2;
echo $a,$b;


Output
12


Question: What will be output of following?
var_dump(0123 == 123);
var_dump('0123' == 123);
var_dump('0123' === 123);


Output
boolean false
boolean true
boolean false


Thursday 10 August 2017

PHP Interview Questions and Answer for 3 year experienced

PHP Interview Questions and Answer for 3 year experienced

Question: What is the difference between Unlink And Unset function In PHP?
unlink It is used to delete the file permanent.
unlink("/data/users.csv");
Unset It is used to delete the variable.
unset($newVariable);



Question: What are PHP Traits?
It is a mechanism that allows us to do code reusability the code and its similer as that of PHP class.
trait Goodmorning {

    public function goodmorning() {
        echo "Good Morning Viewer";
    }

}

trait Welcome {

    public function welcome() {
        echo "Welcome Viewer";
    }

}

class Message {

    use Welcome,
        Goodmorning;

    public function sendMessage() {        
        echo $this->welcome();        
        echo $this->goodmorning();
    }

}

$o = new Message;
$o->sendMessage();

Output
Welcome Viewer
Good Morning Viewer 



Question: How to get URL Of The Current Webpage??
Client side, connect with  parameter



Question: What Is Autoloading Classes In PHP? and how it works?
With autoloaders, PHP allows the to load the class or interface before it fails with an error.
spl_autoload_register(function ($classname) {
    include  $classname . '.php';
});
$object  = new Class1();
$object2 = new Class2();



Question: What s The use of ini_set()?
PHP allows the user to modify its settings mentioned in php.ini using ini_set();
For Example
Display error on page
ini_set('display_errors', '1');

Set mysql connection timeout
ini_set('mysql.connect_timeout',100);

Set maximum execution time
ini_set('max_execution_time',100000);

Set post max size
ini_set('post_max_size','30000M');

Set upload max file size
ini_set('upload_max_filesize','64000M');




Question: Which PHP Extension Helps To Debug The Code?
The name of that Extension is Xdebug.
It uses the DBGp debugging protocol for debugging. It is highly configurable and adaptable to a variety of situations.


Question: How can we get the properties of browswer?
$_SERVER['HTTP_USER_AGENT']



Question: How to get/set the session id?
Set the session Id
session_id($sessionId)

Get the session Id
echo session_id()



Question: What is Scrum?
Scrum is an Agile framework for completing complex projects.
Scrum originally was made for software development projects, but it works well for any complex and innovative scope of work.


Question: What are the ways to encrypt the data?
md5() – Calculate the md5 hash of a string.
sha1() – Calculate the sha1 hash of a string.
hash() – Generate a hash value.
crypt() – One-way string hashing.


Question: How to get cookie value?
$_COOKIE ["cookie_name"];



Question: What is use of header?
The header() function is used to send a raw HTTP header to a client. It must be called before sending the actual output.


Question: What is Type juggle in PHP?
Type Juggling means dealing with a variable type. In PHP a variables type is determined by the context in which it is used.
If an integer value assign to variable it become integer.
If an string value assign to variable it become string.
If an object assign to variable it become object.


Question: What will be output of following?
$x = true and false and true;
var_dump($x);


Output
boolean false


Question: What will be output of following?
$text = 'Arun ';
$text[10] = 'Kumar';
echo $text;


Output
Arun K


Question: What is use of header?
header() is used to redirect from one page to another: header("Location: index.php");
header() is used to send an HTTP status code: header("HTTP/1.0 this Not Found");

header() is used to send a raw HTTP header: header('Content-Type: application/json');


Friday 4 August 2017

php amazing question and logical answer

php  amazing question and logical answer

Question: What is output of 1...1?
Its Output is 10.1
How?
Divide it into three points.
1.
.
.1

  1. 1.0 is equal to 1
  2. 2nd . is a concatenation operator
  3. .1 is equal to 0.1
  4. So {1} {.} {0.1} is EQUAL to 10.1



Question: What is final value of $a, $b in following?
$a = '1';
$b = &$a;
$b = "2$b";
echo $a;
echo $b;
output
21
21

Explaination
$a = '1'; //1
$b = &$a; //both are equal
$b = "2$b"; //now $b=21
echo $a;  //21
echo $b; //21



Question: What is output of 016/2?
Output is : 7. The leading zero indicates an octal number in PHP, so the decimal number 14 instead to decimal 16;
echo 016; //14
echo 016/2; //7



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.

Question: How to start displaying errors in PHP application ? Add following code in PHP.
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

OR
Add following code in .htacess
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on
php_flag  log_errors on




Question: What is stdClass?
It is PHP generic empty class.
stdClass is used to create the new Object. For Example
$newObj = new stdClass();
$newObj->name='What is your name?';
$newObj->description='Tell me about yourself?';
$newObj->areYouInIndia=1;
print_r($newObj);

Output
stdClass Object
(
    [name] => What is your name?
    [description] => Tell me about yourself?
    [areYouInIndia] => 1
)



Question: What is output of below?
$a = '1';
$b = &$a;
$b = "2$b";
echo $a.", ".$b;

output
21, 21


Question:What is the difference between GET and POST?
  1. GET displays the submitted data as part of the URL whereas post does not show.
  2. GET can handle a maximum of 2048 characters, POST has no such restrictions
  3. GET allows only ASCII data, POST has no restrictions, binary data are also allowed.
  4. Normally GET is used to retrieve data while POST to insert and update.



Question:What is traits and give example?
Traits are a mechanism for code reuse in single inheritance languages such as PHP.
class Base {
    public function sayHello() {
        echo 'Hello ';
    }
}

trait SayWorld {
    public function sayHello() {
        parent::sayHello();
        echo 'World!';
    }
}

class MyHelloWorld extends Base {
    use SayWorld;
}

$o = new MyHelloWorld();
$o->sayHello();


output
Hello World



Tuesday 10 January 2017

Redis PHP Interview questions and answers

Redis php interview questions and answers

Question: What is Redis?
Redis is an advanced key-value data store and cache. It has is also referred to as a data structure server as such the keys not only contains strings, but also hashes, sets, lists.


Question: What are the advantages of using Redis?
  1. It provides high speed
  2. It has got command level Atomic Operation (tx operation)
  3. It supports a server-side locking
  4. It has got lots of client lib



Question: What are the limitations of Redis?
  1. It is single threaded
  2. It has got limited client support
  3. It is not deployed



Question: Why Redis is different as compared to other key-value stores?
  1. Redis values can contain more complex data types, with atomic operations.
  2. Redis is an in-memory but persistent on disk database.



Question: How to delete current database?
redis-cli flushdb



Question: How to remove all database?
redis-cli flushall



Question: How to check redis is running?
try {
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    echo "Redis is running.";
    echo "Server is running: " . $redis->ping();
} catch (Exception $e) {
    echo $e->getMessage();
}



Question: How to set value in redis?
$redis->set("name", "Set string in redis");



Question: How to get value from redis?
 echo $redis->get('name'); //Set string in redis



Question: How to set multiple values (Array) in redis?
$redis->lpush("tutorials", "PHP");
$redis->lpush("tutorials", "MySQL");
$redis->lpush("tutorials", "Redis");
$redis->lpush("tutorials", "Mongodb");
$redis->lpush("tutorials", "Mysql");



Question: How to get array data from redis?
$list = $redis->lrange("tutorials", 0 ,5);   
print_r($list);
/*Array ( [0] => Mysql [1] => Mongodb [2] => Redis [3] => MySQL [4] => PHP [5] => Mysql ) */
Question: How to get all keys from redis?
$keyList = $redis->keys("*");
print_r($keyList);
/*Array ( [0] => tutorials [1] => name ) */
Question: How to stop redis?
/etc/init.d/redis-server stop



Question: How to start redis?
/etc/init.d/redis-server start



Question: How to re-start redis?
/etc/init.d/redis-server restart



Question: How do I move a redis database from one server to another?
  1. use BGSAVE command to Save a spanshot of the database into a dump.rdb
  2. Copy this dump.rdb file into another server.