Skip to main content

51 Best PHP Interview Questions and Answers - Rasmus Lerdorf

What Is PHP?
PHP stands for “Hypertext Pre-processors”. It is server side scripting language and used for developing web applications and It's allows us to dynamically create generated web pages.

PHP has many frameworks and CMS and used for creating websites.  The PHP is very easy to create sites using its CMS.  
The PHP is an Object Oriented Programming (OOPs) language.

Is multiple Inheritance supported in PHP?
The PHP includes only single inheritance that means a class can be extended only one single class using extended keyword.

What was the old name of PHP?
The OLD name of PHP is - Personal Home Page.

Who Is the father of PHP?
The father of PHP is - Rasmus Lerdorf.
Rasmus Lerdorf created the PHP Scripting Language, authoring the first two versions of the language and participated in the development of later versions led by a group of developers like –
ü  Jim Winstead
ü  Stig Bakken
ü  Shane Caraveo
ü  Andi Gutmans and
ü  Zeev Suraski

What Is the difference between $name and $$name?
The $name is variable whereas $$name is reference variable like $name=Anil and $$name=Singh so $Anil value is Singh.

What is the difference between $var and $$var?
The $var is a variable with a fixed name. $$var is a variable whose name is stored in $var.

What Is the use of "echo" in PHP?
The "echo" used to print a data in the webpage. Its looks like –
  <?php echo 'Demo apps'; ?>

What Is PEAR in PHP?
The PEAR stands for PHP Extension and Application Repository. The PEAR is a framework and repository and used to create the reusable PHP components. It's also provides a command line interface to install "packages" automatically.
The main purpose of PEAR -
ü  A structured library of open-sourced code for PHP users
ü  A system for code distribution and package maintenance
ü  A standard style for writing code in PHP
ü  PHP Foundation Classes (PFC)
ü  PHP Extension Community Library (PECL)

What Is PDO classes in PHP?
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. It is also data access abstraction layer, so no matter what database we use the function to issue queries and fetch data will be same.

What Is Zend Engine?
The Zend Engine is used internally by PHP as a compiler and runtime engine. The PHP Scripts are loaded into memory and compiled into Zend opcodes and these opcodes are executed and the HTML generated is sent to the client.

What Is the name of scripting engine in PHP?
The scripting engine that powers PHP is called Zend Engine.

What are differences in between PHP4 and PHP5?
The PHP4 doesn't support OOPs concept and it’s using the Zend Engine 1.
The PHP5 supports the OOPs concept and its using the Zend Engine 2.

How do you execute a PHP script from the command line?
The PHP command lines interface (CLI) and specify the file name of the script to be executed as - 
php script.php

How to run the interactive PHP shell from the command line interface?
The PHP CLI program with the option -a as follows -
php -a

How can we display the output directly from the browser?
The tags <?= and ?> is used to display the output directly to the browser.

How To include a file to a PHP page?
The function include () OR require () are using to include a file to a PHP page.

What Are the different type of errors in PHP?
In PHP, contains four types of error -
ü  Parse Error – Commonly caused due to syntax mistakes in codes.
ü  Fatal Error – These are basically run time errors which are caused when you try to access what can’t be done.
ü  Notice Error – These errors occurs when u try to use a variable that hasn’t been declared.
ü  Warning Error – These occurs when u try to include a file that is not present, or delete a file.
What Is the differences between include and require function?
The require () function - The file is required, If file not find - throw Fatal error.
The include () function - If file not find - returns warning not error.

How many data types are there in PHP?
The PHP data types are used to hold different types of data or value and its looks like-
ü  Scalar types
ü  Compound types
ü  Special types

How many Types of Array in PHP?
There are many array functions -
ü  array()
ü  array_change_key_case()
ü  array_chunk()
ü  count()
ü  sort()
ü  array_reverse()
ü  array_search()
ü  array_intersect()

How To declare an Array in PHP?
var $arr = array('Anil', 'Sunil', 'Sushil');

What is the use of "ksort" in PHP?
The “ksort” is used to sort an array by key in reverse order.

What does $GLOBALS means in PHP?
The $GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.

How do you define a constant?
The constants can be defined using define () directive and its looks like -
define("baseUrl", 'https://code-sample.com');

What Is use of in_array() function in PHP?
The in_array() function is used check the values are exists or not in the existing array collection.

What does $_SERVER means in PHP?
The $_SERVER is an array including information created by the web server such as paths, headers, and script locations.

What does $_FILES means in PHP?
The $_FILES is an associative array composed of items sent to the current script via the HTTP POST method.

How To set cookies in PHP?
To set cookies in PHP is –
Setcookie("demoApp", "web", time()+3600);

How To Retrieve a Cookie Value in PHP?
To Retrieve a Cookie Value is –
echo $_COOKIE["demoApp"];

How can we encrypt password in PHP?
The md5 (), sha1 () and base64_encode () functions are used to encrypt the username and password. We can encrypt the password to a degree with md5 () and the md5 () function would be the best.

Example - As for encryption i would personally use md5 () and a salt.
<?php
  $user = "AnilSingh";
  $pass = "Buy a dring first.";
  $salt = "asdfghjkl!";
  $enc_pass = md5(md5($user . $pass) . $salt);
?>

What Are the differences in explode () and str_split () functions?
The str_split() function splits a string into array by using the regular expression.
The explode() function splits a string into array by using the string.

What's a header () function in PHP?
The header () function is used to sends a raw HTTP header to the client browser.

How to set HTTP header to UTF-8 using?
header(‘Content-Type: text/html; charset=utf-8’);

What Is session in PHP?
The Session is a super global variable that preserve the data across subsequent pages. The Session uniquely defines every user with a session ID and its helps to managing the web apps.
The session_id() returns the session id for the current session.

How can we register the variables into a session?
<?php
  session_register($ur_session_var);
?>

How can we destroy a session in PHP?
<?php
   session_destroy();
?>

What Is cookie in PHP?
The Cookie is a small piece of information that stored in the client browser and also used to identify a user using the information stored in their browsers.

What Are differences in ID and class in CSS?
The ID can be used to identify one element but class can be identifying more than one.
The difference between an ID and Class is that an ID can be used to identify one element, whereas a class can be used to identify more than one.

What Are differences in unset() and unlink() function in PHP?
The unset() function is used to destroy a variable and the unlink() function is used to destroy a file.

What does isset() function?
The isset() function is used to checks, the variable is defined and not null.

How can we submit a form without using submits buttons?
document.getElementById("MyformIds").submit();
document.formname.submit();


What are the methods available in form submitting?
The GET and POST are used to submitting a form.

How can we get the browser properties using PHP?
<?php
  echo $_SERVER[‘HTTP_USER_AGENT’].”\n\n”;
  $browser=get_browser(null,true);
  print_r($browser);
?>

What are predefined classes in PHP?
The predefined classes are -
ü  Directory
ü  stdClass
ü  __PHP_Incomplete_Class
ü  exception
ü  php_user_filter

What are magic methods in PHP?
The Magic methods always start with “__” and Magic methods are member functions that are available to all the instance of class.

The Magic Methods are -
ü  __call()
ü  __toString()
ü  __sleep()
ü  __wakeup()
ü  __isset()
ü  __unset()
ü  __autoload()
ü  __clone()
ü  __construct()
ü  __destruct()
ü  __set()
ü  __get()

What's use of __sleep and __wakeup in PHP?
The __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.

What Are the difference between $message and $$message?
The $message stores variable data and the stored data can be fixed while $$message is used to store variable of variables and the stored data may be changed dynamically.

How can I execute an anonymous function in PHP?
call_user_func(function() { echoanonymous function called.’; });

How To send an email In PHP?
Send an email in PHP using the mail () function and It contain five parameters - $to, $subject, $message and $headers. The $message and $headers are optional parameters.

Example -
<?php
   mail($to,$subject,$message,$headers);
?>

What is the difference between characters \034 and \x34?
The \034 is octal 34 and \x34 is hex 34.

I hope you are enjoying with this post! Please share with you friends!! Thank you!!!
By Anil Singh | Rating of this article (*****)

Popular posts from this blog

nullinjectorerror no provider for httpclient angular 17

In Angular 17 where the standalone true option is set by default, the app.config.ts file is generated in src/app/ and provideHttpClient(). We can be added to the list of providers in app.config.ts Step 1:   To provide HttpClient in a standalone app we could do this in the app.config.ts file, app.config.ts: import { ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; import { provideClientHydration } from '@angular/platform-browser'; //This (provideHttpClient) will help us to resolve the issue  import {provideHttpClient} from '@angular/common/http'; export const appConfig: ApplicationConfig = {   providers: [ provideRouter(routes),  provideClientHydration(), provideHttpClient ()      ] }; The appConfig const is used in the main.ts file, see the code, main.ts : import { bootstrapApplication } from '@angular/platform-browser'; import { appConfig } from ...

List of Countries, Nationalities and their Code In Excel File

Download JSON file for this List - Click on JSON file    Countries List, Nationalities and Code Excel ID Country Country Code Nationality Person 1 UNITED KINGDOM GB British a Briton 2 ARGENTINA AR Argentinian an Argentinian 3 AUSTRALIA AU Australian an Australian 4 BAHAMAS BS Bahamian a Bahamian 5 BELGIUM BE Belgian a Belgian 6 BRAZIL BR Brazilian a Brazilian 7 CANADA CA Canadian a Canadian 8 CHINA CN Chinese a Chinese 9 COLOMBIA CO Colombian a Colombian 10 CUBA CU Cuban a Cuban 11 DOMINICAN REPUBLIC DO Dominican a Dominican 12 ECUADOR EC Ecuadorean an Ecuadorean 13 EL SALVA...

39 Best Object Oriented JavaScript Interview Questions and Answers

Most Popular 37 Key Questions for JavaScript Interviews. What is Object in JavaScript? What is the Prototype object in JavaScript and how it is used? What is "this"? What is its value? Explain why "self" is needed instead of "this". What is a Closure and why are they so useful to us? Explain how to write class methods vs. instance methods. Can you explain the difference between == and ===? Can you explain the difference between call and apply? Explain why Asynchronous code is important in JavaScript? Can you please tell me a story about JavaScript performance problems? Tell me your JavaScript Naming Convention? How do you define a class and its constructor? What is Hoisted in JavaScript? What is function overloadin...

25 Best Vue.js 2 Interview Questions and Answers

What Is Vue.js? The Vue.js is a progressive JavaScript framework and used to building the interactive user interfaces and also it’s focused on the view layer only (front end). The Vue.js is easy to integrate with other libraries and others existing projects. Vue.js is very popular for Single Page Applications developments. The Vue.js is lighter, smaller in size and so faster. It also supports the MVVM ( Model-View-ViewModel ) pattern. The Vue.js is supporting to multiple Components and libraries like - ü   Tables and data grids ü   Notifications ü   Loader ü   Calendar ü   Display time, date and age ü   Progress Bar ü   Tooltip ü   Overlay ü   Icons ü   Menu ü   Charts ü   Map ü   Pdf viewer ü   And so on The Vue.js was developed by “ Evan You ”, an Ex Google software engineer. The latest version is Vue.js 2. The Vue.js 2 is very similar to Angular because Evan ...

React | Encryption and Decryption Data/Text using CryptoJs

To encrypt and decrypt data, simply use encrypt () and decrypt () function from an instance of crypto-js. Node.js (Install) Requirements: 1.       Node.js 2.       npm (Node.js package manager) 3.       npm install crypto-js npm   install   crypto - js Usage - Step 1 - Import var   CryptoJS  =  require ( "crypto-js" ); Step 2 - Encrypt    // Encrypt    var   ciphertext  =  CryptoJS . AES . encrypt ( JSON . stringify ( data ),  'my-secret-key@123' ). toString (); Step 3 -Decrypt    // Decrypt    var   bytes  =  CryptoJS . AES . decrypt ( ciphertext ,  'my-secret-key@123' );    var   decryptedData  =  JSON . parse ( bytes . toString ( CryptoJS . enc . Utf8 )); As an Example,   import   React   from ...