PHP Basics



1. What is PHP?  

  • PHP stands for PHP: Hypertext Preprocessor
  • PHP is a server-side scripting language, like ASP
  • PHP scripts are executed on the server
  • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)
  • PHP is an open source software
  • PHP is free to download and use


2. What is a PHP File?  

  • PHP files can contain text, HTML tags and scripts
  • PHP files are returned to the browser as plain HTML
  • PHP files have a file extension of ".php", ".php3", or ".phtml"


3. Why PHP?  

  • PHP runs on different platforms (Windows, Linux, Unix, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP is FREE to download from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side


4. What does the initials of PHP stand for?  

PHP means PHP: Hypertext Preprocessor.



5. Which programming language does PHP resemble to?  

PHP syntax resembles Perl and C


6. What does PEAR stands for?  

PEAR means "PHP Extension and Application Repository". it extends PHP and provides a higher level of programming for web developers.


7. What is the actually used PHP version?  

Version 5 is the actually used version of PHP.


8. How do you execute a PHP script from the command line?  

Just use the PHP command line interface (CLI) and specify the file name of the script to be executed as follows: [crayon-53e4764215d6a784973206/]


9. How to run the interactive PHP shell from the command line interface?  

Just use the PHP CLI program with the option -a as follows: [crayon-53e4764215d7e505856038/]


10. dose PHP support Multiple Inheritance?  

Short Answer

No, PHP does not support multiple inheritance.

Long Answer

Multiple inheritance suffers from the Diamond Problem, which has not been solved in PHP yet. Thus, there is no multiple inheritance in PHP.
    BaseClass
       /\
      /  \
 ClassA  ClassB
      \  /
       \/
     ClassC
If both ClassA and ClassB defined their own method foo(), which one would you call in ClassC?


11. What is final class and a final method in PHP?  

PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended. Example #1 Final methods example

Example #2 Final class example

Note: Properties cannot be declared final, only classes and methods may be declared as final.



12. How comparison of objects is done in PHP5?  

We use the operator '==' to test is two object are instanced from the same class and have same attributes and equal values. We can test if two object are refering to the same instance of the same class by the use of the identity operator '==='.


13. What's the difference between include and require?  

If the file is not found by require(), it will cause a fatal error and halt the execution of the script. If the file is not found by include(), a warning will be issued, but execution will continue.


14. What is difference between require_once(), require() and include() ?  

require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.


15. Differences between GET and POST methods ?  

We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method .


16. How to declare an array in php?  

var $arr = array('apple', 'grape', 'lemon');


17. What is the use of 'print' in php?  

This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.
print('PHP Interview questions');


18. What is use of in_array() function in php ?  

in_array used to checks if a value exists in an array


19. How comparison of objects is done in PHP5?  

We use the operator '==' to test is two object are instanced from the same class and have same attributes and equal values. We can test if two object are refering to the same instance of the same class by the use of the identity operator '==='.


20. What type of operation is needed when passing values through a form or an URL?  

If we would like to pass values througn a form or an URL then we need to encode and to decode them using htmlspecialchars() and urlencode().


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions