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');