Top PHP Interview Questions and Answers

 

Top PHP Interview Questions and Answers :-

Here we are reading about “Top PHP Interview Questions and Answers”.

PHP is a recursive acronym for PHP Hypertext Preprocessor. It is a widely used open-source programming language especially suited for creating dynamic websites and mobile API’s. These Top PHP Interview Questions and Answers are very useful for freshers as well as experienced also.

Facts you Know about PHP

  • Originally Known: Personal Home Page
  • Designed by: Rasmus Lerdorf
  • Written In: C and C++
  • The first official launched: June 1998
  • Current Stable Version: 7.2.9

Q1. What is PHP?

PHP is a server side scripting language commonly used for web applications. PHP has many frameworks and cms for creating websites.Even a non technical person can cretae sites using its CMS.WordPress,osCommerce are the famus CMS of php.It is also an object oriented programming language like java,C-sharp etc.It is very eazy for learning

Q2. What is the use of “echo” in php?

It is used to print a data in the webpage, Example: , The following code print the text in the webpage

Q3. How to include a file to a php page?

We can include a file using “include() ” or “require()” function with file path as its parameter.

Q4. 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.

Q5. require_once(), require(), include().What is difference between them?

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.

Q6. What are the popular Content Management Systems (CMS) in PHP?

  • WordPress
  • Joomla
  • Magento
  • Drupal etc.

Q7. What are the popular frameworks in PHP?

  • CakePHP
  • CodeIgniter
  • Yii 2
  • Symfony
  • Zend Framework etc.

Q8. Which programming language does PHP resemble to?

PHP has borrowed its syntax from Perl and C.

Q9. List some of the features of PHP7.

  • Scalar type declarations
  • Return type declarations
  • Null coalescing operator (??)
  • Spaceship operator
  • Constant arrays using define()
  • Anonymous classes
  • Closure::call method
  • Group use declaration
  • Generator return expressions
  • Generator delegation
  • Space ship operator

Q10. Is multiple inheritance supported in PHP?

PHP supports only single inheritance; it means that a class can be extended from only one single class using the keyword ‘extended’.

Q11. What is the meaning of a final class and a final method?

‘final’ is introduced in PHP5. Final class means that this class cannot be extended and a final method cannot be overridden.

Q12. How is the comparison of objects done in PHP?

We use the operator ‘==’ to test is two objects are instanced from the same class and have same attributes and equal values. We can test if two objects are referring to the same instance of the same class by the use of the identity operator ‘===’.

Q13. How can PHP and HTML interact?

It is possible to generate HTML through PHP scripts, and it is possible to pass pieces of information from HTML to PHP.

Q14. How can PHP and Javascript interact?

PHP and Javascript cannot directly interact since PHP is a server side language and Javascript is a client-side language. However, we can exchange variables since PHP can generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.

Q15. What is needed to be able to use image function?

GD library is needed to execute image functions.

Q16. What is the use of the function ‘imagetypes()’?

imagetypes() gives the image format and types supported by the current version of GD-PHP.

Q17. What are the functions to be used to get the image’s properties (size, width, and height)?

The functions are getimagesize() for size, imagesx() for width and imagesy() for height.

Q18. Where sessions stored in PHP ?

PHP sessions are stored on server generally in text files in a temp directory of server.
That file is not accessible from outside word. When we create a session PHP create a unique session id that is shared by client by creating cookie on clients browser.That session id is sent by client browser to server each time when a request is made and session is identified.
The default session name is “PHPSESSID”.

Q19. How Can We Know The Number Of Days Between Two Given Dates Using Php?

Simple arithmetic:
$date1 = date(‘Y-m-d’);
$date2 = ‘2006-07-01’;
$days = (strtotime() – strtotime()) / (60 * 60 * 24);
echo “Number of days since ‘2006-07-01’: $days”;

Q20. How Can We Repair A Mysql Table?

The syntex for repairing a mysql table is:

REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
REPAIR TABLE tablename EXTENDED

This command will repair the table specified.
If QUICK is given, MySQL will do a repair of only the index tree.
If EXTENDED is given, it will create index row by row.

Q21. How To Get The Uploaded File Information In The Receiving Script?

Once the Web server received the uploaded file, it will call the PHP script specified in the form action attribute to process them. This receiving PHP script can get the uploaded file information through the predefined array called $_FILES. Uploaded file information is organized in $_FILES as a two-dimensional array as:

  • $_FILES[$fieldName][‘name’] – The Original file name on the browser system.
  •  $_FILES[$fieldName][‘type’] – The file type determined by the browser.
  •  $_FILES[$fieldName][‘size’] – The Number of bytes of the file content.
  •  $_FILES[$fieldName][‘tmp_name’] – The temporary filename of the file in which
    the uploaded file was stored on the server.
  •  $_FILES[$fieldName][‘error’] – The error code associated with this file upload.
    The $fieldName is the name used in the .

Q21. What Is The Difference Between Mysql_fetch_object And Mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

Q22. How Can I Execute A Php Script Using Command Line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program.
Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

Q23. I Am Trying To Assign A Variable The Value Of 0123, But It Keeps Coming Up With A Different Number, What’s The Problem?

PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.

Q24. Would I Use Print “$a Dollars” Or “{$a} Dollars” To Print Out The Amount Of Dollars In This Example?

In this example it wouldn’t matter, since the variable is all by itself, but if you were to print something like “{$a},000,000 mln dollars”, then you definitely need to use the braces.

Q24. What is use of the header() function in PHP?

  1. header() is used to redirect from one page to another: header(“Location: index.php”);
  2. header() is used to send an HTTP status code: header(“HTTP/1.0 this Not Found”);
  3. header() is used to send a raw HTTP header: header(‘Content-Type: application/json’);

So in this article we learned about “Top PHP Interview Questions and Answers”.

Read more About :-

Top Node.js Interview Questions and Answers

Leave a Reply

Your email address will not be published. Required fields are marked *


CAPTCHA Image
Reload Image