Loading

PHP Interview Questions

PHP Interview Questions answers

PHP is currently more popular web technology scripting language. Here I am putting general PHP interview questions answers

1. What is PHP ?
Ans:- PHP stands for Hypertext Processor. It is open source scripting language. Rasmus Lerdorf develop PHP in year 1994 and he known as Father of PHP. PHP old name is Personal Home Page
Normally PHP is used for developing dynamic website.

2. What is PEAR in PHP?
Ans:- PEAR stands for PHP Extension and Application Repository. It is PHP framework and repository for reusable PHP component.

3. what is the difference b/w static and dynamic websites?
Ans:-
Static website :- We cannot change anything in website and after running script content can not change. Over all we cannot change any things in running site.
Dynamic Website :- content of the Script can be change at run time. Content can be regenerated after every visit of user.

4. What is the name of scripting engine in PHP?
Ans:- Zend Engine 2 is a scripting engine in PHP. It compile PHP code and give output in HTML format.

5. Explain the difference between PHP4 and PHP5.
Ans:- PHP4 use Zend Engine 1 and It does not support object oriented programming.
PHP5 use Zend Engine 2 and It support Object Oriented Programming.

6. What is the recent version of PHP?
Ans:- Current version of PHP is 7.x (7.1 , 7.2)

7. How to execute PHP script using Command Line?
Ans:- Using PHP command line interface (CLI) we can execute PHP script.
php filename.php;

8. How to run PHP interactive shell in command Line?
Ans:- Using PHP CLI Program after using option -a
php -a

9. Common way to start and finish PHP block of code?
Ans:- There are following common ways :-
<?php …… ?> and <? …….. ?>

10. How PHP display output directly to the browser?
Ans:- For display output directly to the browser, we have to use specific tag <?= and ?>

11. What are the popular Content Management Systems (CMS) in PHP?
Ans:- Popular content management Systems(CMS) in PHP are:-
Wordpress, Joomla, Drupal, Magento, etc.

12. What are the popular frameworks in PHP?
Ans:- Popular frameworks in PHP are :-
CakePHP, CodeIgniter, Yii 2, Symfony, Zend Framework, Laravel, etc.

13. Which programming language PHP resemble to?
Ans: PHP syntax taken from C and Perl

14. What is the features of PHP7?
Ans:- There are following features are PHP 7 :-
a. Scalar type declarations :- Scalar type declaration comes in two flavor first default is Coercive and second is strict.
b. Return type declaration
c. Null Coalescing Operator and Symbol is ??
d. Spaceship Operator
e. Constant array using define
f. Anonymous Class
g. Unicode Codepoint escape syntax
h. Closure::call() :- Closure::call()is a more performant, shorthand way of temporarily binding an object scope to a closure and invoking it.
i.Filtered Unserialize()
j. IntlChar
k. Expectations
l. Group use declarations
m. Generator return Expressions
n. Generator Delegation
o. Integer Division with intdiv()
p. Session Options
q. preg_replace_callback_array()
r. CSPRNG Functions :- random_bytes() and random_int()
s. list() can always unpack objects implementing ArrayAccess
t. Class member access on cloning has been added, e.g. (clone $foo)->bar().

15. What is the difference between “echo” and “print” in PHP?
Ans:- Echo and Print both are language construct.
Echo can output one or more string but print can only output one string and always returns 1.
Echo is faster than print because it does not return any value.

16. How a variable is declared in PHP?
Ans:- In PHP variable is a temporary storage area in memory. which is declared using $ sign.
Example:- $variablename = value;

17. What is the difference between $message and $$message?
Ans:- $message is a variable and $$message is a variable of variable $message.
$message is fix date but $$message may be change dynamically.

18. How constant can be define in PHP?
Ans:- In PHP constants can be define from following two functions
define() function
const() function

19. What are magic constants in PHP?
Ans:- magic constant is predefine constant and it change on the basis of their use. It start from double underscore (__)
Some magic constants are :-

Name Description
__LINE__ Represents current line number where it is used.
__FILE__ Represents full path and file name of the file. If it is used inside an include, name of included file is returned.
__DIR__ Represents full directory path of the file. Equivalent to dirname(__file__). It does not have a trailing slash unless it is a root directory. It also resolves symbolic link.
__FUNCTION__ Represents the function name where it is used. If it is used outside of any function, then it will return blank.
__CLASS__ Represents the function name where it is used. If it is used outside of any function, then it will return blank.
__TRAIT__ Represents the trait name where it is used. If it is used outside of any function, then it will return blank. It includes namespace it was declared in.
__METHOD__ Represents the name of the class method where it is used. The method name is returned as it was declared.
__NAMESPACE__ Represents the name of the current namespace.

20. Data types in PHP?
Ans:- In PHP three data type, It used for hold different value or data.
1. Scalar Types
a. boolean
b. integer
c. float
d. string
2. Compound Type
a. array
b. object
3. Special Type
a. resource
b. NULL

21. Comments in PHP?
Ans:- We can use following comments in PHP
a. Single Line comment // (C++ style comment)
b. #(Unix style comment)
c. Multi line comment /* */

22. Loops in PHP?
Ans :- There are following loops in PHP :-
for, while, do while, foreach

23. Use of count() function in PHP?
Ans :- count() function count total number of element in an array or an object.

24. What is header() function in PHP?
Ans :- header() function is used for send raw HTTP to the client. It must be used before any actual output.

25. what is isset() function in PHP.
Ans :-isset() function check variable define or not. It return true or false.

26. PHP parameterize functions are?
Ans :- Those functions in a PHP which holds parameter are called parameterize function. For example
function myfunction($a, $b){
echo “$a and $b are parameter”;
}
we can pass any number of parameters inside a function.

27. What is PHP variable length argument?
Ans :- From PHP version 5.6 introduce variable length argument. using dot (.) we can pass 0, 1 and nth number of argument in a function. For example:-
function sum(…$num) {
$count = 0;
foreach ($num as $n) {
$count += $n;
}
return $count;
}

28. Explain Array in PHP?
Ans :-Array store multiple value in single variable. In PHP, array store value in a form of key and value. It store collection of data type,
PHP support three type of array:-
Indexed array
Associative array
Multidimensional array

29. Write a list of PHP array function?
Ans :- There are following common PHP array functions:-
array() -> It crate array
array_change_key_case()-> change the case of all keys in an array.
array_chunk()-> Split an array into chunk
array_column()->Return the values from single column in the input array.

30. PHP array sort functions?
Ans :- Following are array sort functions:-
sort() -> sort an array
asort()-> sort an array associatively
ksort()-> sort an array by key
rsort()-> sort an array in reverse order
usort()-> sort an array by values using user defined comparison function
arsort()->sort an array in reverse order and maintain an index associative.
krsort()-> Sort an array by key in reverse order
uksort()-> Sort an array by key using user defined comparison function

31. Difference between Index and Associative array?
Ans :- Those array which holds key value in an indexed from which is represented by number like 0, 1, 2 3,etc. Is known as Index array.
Those array which holds element with name is called Associative array.

32. Php strlen() function is used for?
Ans :- strlen() function is used for get the length of a string.

33. Explain five PHP string functions?
Ans :- There are following five string functions are :-
addslashes() ->quote strings with slashes
explode()-> Split stringby string
htmlentities()-> Convert all applicable character to HTML entities
implode()-> Join array with a string
nl2br()->Insert HTML line break into a string

34. PHP method of Submit form?
Ans :- GET and POST are two methods.

35. How we can submit a form without using submit button in PHP?
Ans:- Using Javascript submit() function , we can submit a form without using submit button.

36. How we can include a file in PHP script?
Ans :- There are following functions :-
include
include_once
required
required_once

37.What is the difference between include() and require() function?
Ans :-Require and include both are used for including file in PHP script. But if file not found include produce warning message and require produce fatal error.

38. What is setcookie() function in PHP?
Ans :- setcookie() is used for set cookie with HTTP response. Once cookie is set then we can call it with super global variable $_COOKIE[]

39. How to get cookie value?
Ans :-$_COOKIE[‘username’];

40. What is session in PHP?
Ans :- In PHP session maintains data of an users browser. session generally store temporary data. Session store data in serialize format.
Over all PHP session is a logical object which is created by PHP engine and it preserve data across subsequent HTTP requests.

41. How session register a variable?
Ans :-
< ?php Session_register($user_session_var); ? >

42. What is $_SESSION in PHP?
Ans :- $_SESSION is a global variable in PHP, which is used for get and set session variable. It is an associative array which contain all session variable.

43. Explain session_start() function in PHP?
Ans :- session_start() function is used for start a session. It either start new session or resume existing session.

44. Explain session_destroy() function in PHP?
Ans :- session_destroy() is used for end the session.

45. What is the difference between session and cookie?
Ans :-There are following difference between session and cookie:-
1. Cookie store data into user computer using text file. While session store data into the server
2. cookie can not hold multiple variable. while session can hold multiple variable
3. Cookie can manually set expiry time. session can expire when browser close.

46.How to open a file in PHP?
Ans :-fopen() function is used for file open in PHP. It take two parameters filename and mode.

47. How to read a file in PHP?
Ans :- There are following function is used for read a file in PHP:-
fread()
fgets()
fgetc()

48. How to write a file in PHP?
Ans :- fwrite() and fputs() function are use for write a file.

49. How to delete a file in PHP?
Ans :- unlink() function is use for delete a file in PHP.

50. How to execute PHP script in command line?
Ans :- Using command line interface (CLI) we can execute PHP script.

Share with:


6+

2 thoughts on “PHP Interview Questions

  1. I think It will be help full for all PHP professional who want to crack PHP interview.

    0

Leave a Reply

Connect with:




z35W7z4v9z8w