Monday, March 24, 2014

PHP Interview Questions.


 PHP Interview Questions.

 As PHP language is in trend nowadays that’s why all web developing companies give priority to those candidates who are good in PHP language. These companies hire the desired candidates who have a good knowledge of HTML language as well as PHP language & ask them the following PHP Interview Questions.

Frequently Asked PHP Interview Questions

What is PHP?
PHP is an open source scripting language which is widely used nowadays. The full form of PHP is Hypertext Pre-processor.

What is a PHP File?
Those files which contain text, HTML, JavaScript code, and PHP code are known as PHP files. The default file extension of PHP files is “.php”.

What is the current version of PHP, Apache, MySQL?
The current version of PHP is php 5.1.2, the current version of Apache is Apache 2.1 and the current version of MySQL is MySQL 5.1.

What are the uses of PHP language?
The main uses of PHP language are following:-
1. PHP language is used to generate dynamic page content.
2. Through PHP language user can create, open, read, write, and close files on the server.
3. User can collect form data through PHP language.
4. You can send and receive cookies with the help of PHP language.
5. User can add, delete and modify data in your database through PHP language.

Why we use PHP over other languages?
We use PHP language over other languages beacuse PHP language runs on different platforms like Windows, Linux, Unix, Mac OS X, etc. It is also compatible on all servers like Apache, IIS, etc.

In PHP language, what does a special set of tags <?= and ?> do?
The use of special set of tags in PHP language is to display the output of the program directly to the browser.

What is the common difference b/w include and require in PHP language?
In PHP language the functions include and require are used to handle the failures in a program. The common diffrence between include and require in PHP language is that in case of include function, if the file of any program is not found by include() then it shows a warning to the user but side by side the execution of the script will continue. In case of require function in PHP language, if the file of any program is not found by the rquire() then it shows a fatal error to the user and also it halt the execution of the script.


What is the main problem arising when you assign a variable having value 0123 and it shows a different number (value)?
The number begins with 0 is treated as octal by the interpreter in PHP language. That’s why it gives the different number.

What is the correct way to print the amount of dollars – “$a dollars” or “{$a} dollars”?
In the above example both ways are correct to print out the amount of dollars. but if you want to print the “{$a},000,000 million dollars”then you surely need to use the braces.

Define a constant in PHP language?
The constant in PHP language is defined by the syntax define() directive. For example-  (“MYCONSTANT”, 230);

How do you pass a variable by value?
In PHP language you can pass a variable by value simply by putting the sign of ampersand in front of the variable which is same as in C++. For example $a = $c.

In PHP language, Will comparison of string “10″ and integer 11 work?
Yes, in PHP language we can compare the string “10″ and integer 11 because both the nos. are of integer type and PHP support the integer type string and numbers.

When will you need to use endif statement to end the conditional statement?
We will need to use the endif statement in PHP language when the original if statement was followed by. Then we will code the block without braces.

Define the ternary conditional operator in PHP language?
Ternary conditional operator in PHP language is defined by the given statements….. When the expression preceding the ? is evaluated and if it is found to be true, then the expression preceding the : will be executed, otherwise, the expression following : is executed.

How to find out the no. of parameters passed into function in PHP language?
The no. of parameters passed into function in PHP language by the given syntax. func_num_args() , Through this the function returns the no. of parameters passed into function.

If the variable $b is equal to 5 and variable $c is equal to character b, what’s the value of $$a?
The value of $$a is equal to 100. It is the reference to existing variable.

What is the main difference b/w accessing a class method via -> and via ::?
The main difference between accessing a class method via -> and via :: is that when we we use :: then it is used to allow to access methods by which we can perform static operations. And in case of ->, we don’t need to initialize the object to access a class method.

In PHP language, are objects passed by reference or by value?
In PHP language, user can pass not even object but also user can pass everything by value.

How do you call a constructor for a parent class in PHP language?
We can call a constructor for a parent class in PHP language by the given syntax. Example:- parent::constructor($value)

What is the special meaning of __sleep and __wakeup in PHP language?
Meaning of ___sleep:- It returns the array of all the variables which need to be saved. Meaning of ___wakeup:- It is used to retrieve the array of all the variables.
Here is a code is given…
<?php
$str = ‘Hello, there.nHow are you?nThanks for visiting Our Website’;
print $str;
?>

Why the above code does not print the new line properly?
The above code does not print the new line properly because the n character does not interpret the code in new line when n character is written or used inside the single quotes.

Would you initialize your strings with single quotes or double quotes?
It is easy and efficient to use the single quotes to initialize the string as the data inside the single-quoted string is not parsed for variable substitution. So it is better to use single quotes rather than we using double quotes to initialize the string.

Code <?php print “Contents: $arr[1]“; ?> works, but <?php print “Contents: $arr[1][2]“; ?> doesn’t work for two-dimensional array of mine, What is the main reason behind it?
You must required complex parsing syntax in case of using array with more than one dimension. That’s why the first code works properly and second given doesn’t work properly in PHP language. print “Contents: $arr[1][2]“;  would have been worked if we are using the complex parsing syntax.

What is the common difference between characters 23 and x23 in PHP language?
The common difference between characters 23 and x23 is that the character 23 is octal 23 and the character x23 is hex 23 in PHP language.

With a heredoc syntax, do you get variable substitution inside the heredoc contents?
Yes, you get the variable sunstitution inside the heredoc contents with a heredoc syntax.

If we combine two variables together. For example:
$var3 = ‘Welcome to ‘;
$var4 = ‘Our Website’;
What will work faster?
Code example 1st: $var 3 = $var1.$var2; or Code example 2nd: $var3 = “$var1$var2″; ?
The above both the examples gives you the same result. $var3 equal to “Welcome to Our Website”. However, Code example 1st will work significantly faster than the code example 2nd.



1 comment:

  1. Good information shared about php..Share some tips to understand it easily..
    شوفي

    ReplyDelete

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide

How to Host a Laravel Project on Hostinger’s hPanel: A Step-by-Step Guide If you're looking to host a Laravel project on Hostinger’s hPa...