Quick Contact

    Top 25 PHP Interview Questions For Fresher To Prepare in 2022

    1. What is PHP?


      The Hypertext Preprocessor is a server-side scripting language which is open source and extensively used for the development of dynamic web applications. RasmusLerdorf, commonly known as the founder of PHP, created it in 1994.

      We didn’t have to inform PHP what sort of Datatype a Variables is since PHP is a dynamically typed language. PHP changes the variables to the appropriate datatype based on its value.

    2. Where sessions stored in PHP?

      PHP sessions are often saved on the server as text documents inside the server’s temporary directory.

      The outside world cannot access the data. When we construct a session, PHP creates a unique session ID which the client shares by placing a cookie on the client’s browser. Whenever a request is performed as well as the session is detected, the clients browser sends that session identity to the server.

      “PHPSESSID” is the default session name.

    3. Write down the benefits of PHP7?

      PHP7 is an advance in the programming language, having features that outperform all previous versions. It provides several advantages to PHP programmers, including:

      • Increase speed-

        Programmers have already been working very hard to increase speed while decreasing storage use, and their efforts have finally succeeded. PHP7 provides 50% higher performance than PHP5 while simultaneously consuming 50% less resources.

      • Allows for error handling-

        Handling errors has always been a time-consuming issue for PHP programmers. However, with the most recent PHP7 upgrade, engine exceptions would allow developers to deal and fix these mistakes with exceptions. If the exceptions are not caught, PHP will continue to deliver errors like PHP5.

      • 64-bit Windows support-

        PHP7 is compatible with 64-bit platform PCs.

      • Anonymous classes-

        A new class in PHP7 supports anonymous classes. This may be used instead of creating new class definitions.

      • New spaceship and null coalescing operators-

        This PHP7 feature compares two expressions. PHP’s type comparison rules are used to conduct the comparisons. It facilitates the sorting process.

    4. What are constructor and destructor in PHP ?

      PHP constructor and destructor are special type operations which are called whenever a PHP class instance is produced or destroyed.

      In general, Constructors are used to establish the class’s private parameters, whereas Destructors are used to liberate the resources created/used by the class.

      In PHP, here’s an example of constructor and destructor.

      < ?php class Foo { private $name; private $link; public function __construct($name) { $this->name = $name;
      public function setLink(Foo $link){
              $this->link = $link;
      public function __destruct() {
      echo 'Destroying: '. $this->name;
    5. How to register a variable in PHP session ?

      We may register a variable session_register() method in PHP 5.3 or previous versions. It has been discontinued, and we may put a value immediately in $_SESSION Global.

      Example usage:

      < ?php // Starting session session_start(); // Use of session_register() is deprecated $username = "PhpScots"; session_register("username"); // Use of $_SESSION is preferred $_SESSION["username"] = "PhpScots"; ?>
    6. What is use of @ in Php ?

      In PHP,@ is used in PHP to block error messages. When we put @ before any statement in PHP, if a runtime error occurs on a certain line, PHP handles the error.

    7. Is multiple inheritance supported in PHP ?

      No, In PHP multiple inheritance is not supported.

    8. What is namespaces in PHP?

      PHP Namespaces allow you to group together similar classes, interfaces, methods, and constants.

      # define namespace and class in namespace
      namespace Modules\Admin\;
      classCityController {
      # include the class using namesapce
      use Modules\Admin\CityController ;
    9. What is a composer in PHP?

      It is a PHP flexible and adaptive management. It enables you to specify the packages over which your project depends and manages (installs/updates) them for you.

    10. What is cURL in PHP ?

      cURL is a PHP package which allows you to send HTTP requests to a server.

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

      • WordPress:

        WordPress is an free and open-source content management system (CMS) that runs on PHP and MySQL. It has a plug-in architecture as well as a template system. It is commonly associated with blogging, although it also enables various types of web content, like as more conventional mailing lists and newsgroups, media presentations, and online commerce.

      • Joomla:

        Open-sourced Enterprises, Inc. built Joomla, a free and open-sourced content management system (CMS) for publishing web content. It is built on a prototype web application framework which can be deployed without the need for a CMS.

      • Magento:

        Magento is an open source E-commerce programming developed by Varien Inc. that is useful for online businesses. It features a varied measured design and several control options that are beneficial to clients. Magento makes use of an E-commerce platform that provides organisations with advanced E-business solutions and a large support network.

      • Drupal:

        Drupal is a content management system (CMS) platform written in PHP and published under the GNU General Public License (General Public License).

    12. What are the popular frameworks in PHP?

      Following are the popular frameworks in PHP:

      • CakePHP
      • CodeIgniter
      • Yii 2
      • Symfony
      • Zend Framework etc.
    13. What is “echo” in PHP?

      PHP echo returns a single or several strings. It’s a verbal construct, not a function. As a result, the usage of parenthesis is not necessary. However, if you wish to send more than one argument to echo, you must use parentheses.


      void echo ( string $arg1 [, string $… ] )

    14. What is “print” in PHP?

      PHP print returns a string. It’s a linguistic construct, not a function. As a result, the argument list does not necessitate the usage of parenthesis. In contrast to echo, it always returns 1.


      int print ( string $arg)


      Echo can output one or more string but print can only output one string and always returns 1 whereas Echo is faster than print because it does not return any value.

    15. What are magic constants in PHP?

      PHP magic constants are preset constants that alter depending on how they are used. They begin with two underscores (__) and finish with two underscores (_).

    16. Explain PHP parameterized functions.

      PHP parameterized functions are those that have parameters. A function can utilize any number of variables. These arguments are used as variables throughout the function. They are supplied just after function definition, inside the parenthesis. The function’s output is determined by dynamic values supplied as arguments.

    17. Describe array and its types in PHP?

      An array is a type of data structure that stores numerous values in a single value. It arranges maps of key-value pairs using PHP. It stores the data type gathering.

      In PHP, there are three types of arrays:

      1. Indexed array:

        an array with a numeric key.

      2. Associative array:

        an array where each key has its specific value.

      3. Multidimensional array:

        an array containing one or more arrays within itself.

    18. What is a session?

      The PHP Engine produces a logical object called a session to save data between HTTP requests. Sessions often keep temporary data in order for several PHP pages to provide a fully working transactions for the same user.Basically defined, it stores a user’s info (browser).

    19. What is the difference between session and cookie?

      The primary distinction between a session and a cookie is that cookies are saved on the user’s computer in text format, whereas sessions are stored on the server.Cookies, on the other hand, cannot contain many variables, whereas Session can.A cookie may be configured to expire at any time, but a session is only active as long as the browser is open.

    20. How do you connect MySQL database with PHP?

      There are two ways to link the MySQL database to PHP. Style is procedural and object-oriented.

    21. How to create connection in PHP?

      The mysqli_connect() function is used to create a connection in PHP.

      resource mysqli_connect (server, username, password)

    22. How to create database connection and query in PHP?

      Since PHP 4.3, mysql_reate_db() is deprecated. Now you can use the following 2 alternatives.

      • mysqli_query()
      • PDO::_query()
    23. What are include() and require() functions?

      The Include() method is used to copy data from one PHP file towards another. When an error occurs, the include() method issues a caution but does not halt the script’s performance; it will continue to run.

      The Require() method may also be used to copy data from one PHP script to another. When there are any errors, the need() method generates a warning and a fatal error, and the script is terminated.

    24. What is the Importance of Parser in PHP?

      The PHP parser reads the PHP-created webpage from start to finish. Tags specify the start and the end points of PHP code. In other words, the reach of PHP scripting syntax is determined by the opening and closing tags in PHP.

      < ?syntax of opening tag in PHP

      ?> syntax of closing tag in PHP

    25. How can we create a database using PHP and MySQL?

      The following are the steps required to build a MySQL database using PHP:

      • From the PHP script, connect to the MySQL server.
      • If the connectivity is successful, build a database and put the SQL query in a strings variable.
      • Execute the query.

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.