Request a Call back


captcha

PHP Interview Questions

Frequently Asked Interview Questions And Answers For PHP Freshers

What Are The Common Uses Of PHP?

-> We can choose files from the system and can perform open, read, write operations on one system.
-> We can perform operations on a form like saving data from a form to send data to the server.
-> You can add, delete, modify elements within your database with the help of PHP.
-> We can create cookies and set cookies on the elements.
-> We can put some restrictions on any PHP pages about accessing it.

What is PEAR in PHP?

PEAR is a framework and repository for reusable PHP components. PEAR stands for PHP Extension and Application Repository. It contains all types of PHP code snippets and libraries. It also provides a command line interface to install “packages” automatically.

What is The Difference Between Static and Dynamic Websites In PHP?

Static Websites:
-> Static website the content is not changed after changes in the script.

Dynamic Websites:
-> Dynamic website’s content is changed after the changes in the script.

How To Execute a PHP Script From The Command Line?

To run any program we have to use the PHP command line by writing the file name in it.

PHP script.php

Is PHP A Case Sensitive Language?

In PHP, all the user-defined functions are not case sensitive, we can call the function written in lowercase by writing in uppercase but other elements are case sensitive.

What Is The Meaning Of ‘Escaping To PHP’?

Escaping to PHP means to distinguish the PHP code from other elements.

What Are The Characteristics Of PHP Variables?

Some of the important characteristics of PHP variables include:
• All variables in PHP are denoted with a leading dollar sign ($).
• The last assigned value to a variable is it’s the latest value.
• The variables are assigned value by using = assignment operator, the left side contains variable and the right side contains the value to be assigned to the variables.
• Variables are mostly declared when it needs to be used for assignment.
• The variables aren’t declared with its types already, it doesn’t know about in which type it is going to be used.
• Variables used before they are assigned have default values.

What Are The Different Types Of PHP?

There are 8 data types in PHP which are used to construct the variables:
1. Integers – Integers are whole numbers, without a decimal point, like 4195.
2. Doubles – Doubles are floating-point numbers, like 3.14159 or 49.1.
3. Booleans – Booleans have only two possible values either true or false.
4. NULL − is a special type that only has one value: NULL.
5. Strings – Strings are sequences of characters, like ‘PHP supports string operations.’
6. Arrays – Arrays are like boxes that are named and indexed collections of other values.
7. Objects Instance of the class that is used to access the functions of the class called objects.
8. Resources − Resources are used to store the reference of the resource outside of PHP.

What Are The Rules For Naming A PHP Variable?

The following rules are needed to be followed while naming a PHP variable:
• Variable names must begin with a letter or underscore character.
• A variable name can consist of numbers, letters, underscores but you cannot use characters like + , – , % , ( , ) . & , etc.

What Are The Rules To Determine The “Truth” Of Any Value Which Is Not Already Of The Boolean Type?

The rules to determine the “truth” of any value which is not already of the Boolean type are:
• If it values is a number it is false or if it’s equal to zero or anything it is true.
• If it’s a value is a string it is false or if its string is equal to ’0’ or anything it is true.
• Values of type NULL are always false.
• If the array contains the value it is false if the array contains no value or anything else it is true.
• Valid resources are true (although some functions that return resources when they are successful will return FALSE when unsuccessful).
• Don’t use double as Booleans.

What is NULL?

Null can have only one value assigned to it, the variable has null value means it has no value assigned to it. It can be assigned as follows:

$var = NULL;

The constant NULL is written in the capital but it is case sensitive. We can write it as:

$var = null;

A variable that has been assigned the NULL value consists of the following properties:
• It evaluates to FALSE in a Boolean context.
• It returns FALSE when tested with IsSet() function.

How Do You Define A Constant in PHP?

We can use Define() function to get the value of a constant, we can’t change or undefine it. We can use the letter or underscore to use constantly.

What Is The Purpose Of Constant() Function?

When we don’t know the name of the constant and we want the value of it then we can use Constant() to retrieve the value of constant.it may happen in the case when it is stored in a variable or returned by a function.

What Are The Differences Between PHP Constants and Variables?

Constants:
-> We can use constantly without writing Dollar sign before it.
-> We can define the
-> We can access the constant from anywhere far from any scoping rules.
-> We cannot undefined or redefine the constants.

Variables:
-> We have to write a dollar sign before a variable to use it.
-> We can define the variable by assignment operation.
-> We can access the variables which are created by functions automatically.
-> We can redefine variables independently.

Name Some Of The Constants in PHP and Their Purpose.

1.) _LINE_ – we can use it to show the current line number of the file.
2.) _FILE_ – we can use it to show the name and full path of the file .when used in inside include, the name of the file is returned which is included.
3.) _FUNCTION_ – we can use it to show the function name
4.) _CLASS_ – this constant returns the class name.
5.) _METHOD_ – it shows the method name.

What Is The Purpose of Break and Continue Statement?

Break – We can use the break statement to break the for loop or the switch conditional statements and transfers the control to the next statement.

Continue – We can use continue statement to stop breaking the loop and transfer the control again to the condition.

What Is The Difference Between PHP4 and PHP5?

PHP4:
• Both constructor and class names are the same.
• We can pass everything by value.
• In PHP4 we cannot declare a class as abstract.
• We can’t use static methods and properties in class in PHP4.

PHP5:
• The Constructors are defined as _construct() and Destructor areas District().
• We can pass objects by the reference.
• In PHP5 we can declare the class as abstract.
• We can use static methods and properties in PHP5.

What Is The Meaning Of a Final Class And A Final Method?

We can use the final class to protect it to be subclassed in the case of creation of immutable class like the String class.we can not declare properties as final only methods can be declared as final.

How Can You Compare Objects In PHP?

Operator ’==’ is used to comparing the two objects if they both are instantiated from the same class and can test their attributes and equal values, we use ‘===’ operator to identify that the instances are referencing to the same two objects of the same class.

How Can PHP And JavaScript Interact?

PHP is server-side language and javascript is a client-side language so both cannot connect directly but javascript can send some variables back to PHP by using URL and PHP can generate some javascript code to be executed by the browser.

How Can PHP and HTML Interact?

Using HTML, it is a client-side language and we can send the data to the server. PHP is a server side language that can execute the server and send the data in the form of strings, arrays objects and can display in HTML.

Name Some Of The Popular Frameworks in PHP

These are the most popular frameworks of the PHP:
• CakePHP
• CodeIgniter
• Yii 2
• Symfony
• Zend Framework

What Are The Data Types in PHP?

PHP support 9 primitive data types:
1) Scalar Types:
• Integer
• Boolean
• Float
• String

2) Compound Types:
• Array
• Object
• Callable

3) Special Types:
• Resource
• Null

What Are Constructor And Destructor in PHP?

In PHP, constructor and destructors are called when the object of the class is created and destroyed. A constructor is used to pass the parameters with the creation of the object to initialize the variables of the instance.

Here is an example of constructor and destructor in PHP:

;name = $name;
}

public function setLink(Foo $link){
$this->;link = $link;
}

public function __destruction() {
echo ‘Destroying: ‘, $this->name, PHP_EOL;
}
}
?>

What Are Include() and Require() Functions?

We can use Include() function to transfer one file’s data into another file.it doesn’t stop e\the execution if any error occurs it continues the execution and provides a warning.

We can use Require() to transfer the data of one PHP file to another file here if any error occurs it stops the execution with the fatal error on the screen.

What Is The Main Difference Between Require() and Require_Once()?

The Require evaluates a file but require_once () does that only if the specified file is not included .required_once is used to include a PHP file into another file. When we have lots of functions than its good to use required_once().

What Are Different Types of Errors Available in PHP?

The different types of error in PHP are:
• E_ERROR– A fatal error that causes script termination.
• E_WARNING– It is a runtime error but it won’t stop the script termination.
• E_PARSE– It’s a Compile-time parse error.
• E_NOTICE– It occurs because of runtime error in the code.
• E_CORE_ERROR– Fatal errors that occur during PHP initial startup.
• E_CORE_WARNING– Warnings that occur during PHP initial startup.
• E_COMPILE_ERROR– These are Fatal compile-time errors that indicate a problem with a script.
• E_USER_ERROR– User-generated error message.
• E_USER_WARNING– User-generated warning message.
• E_USER_NOTICE- User-generated notice message.
• E_STRICT– Run-time notices.
• E_RECOVERABLE_ERROR– Catchable fatal error indicating a dangerous error
• E_ALL– Catches all errors and warnings.

Explain The Syntax For ‘foreach’ Loop With Example.

It is used in arrays to the value of the current array element in every pass it is assigned to $value and the pointer is transferred to the next one.
Syntax-
foreach (array as value)
{
code to be executed;
}
Example-

“;
}
?>

What Are The Different Types of Array in PHP?

There are 3 types of Arrays in PHP:
1. Indexed Array Indexed arrays are the one that has a numberic index and are in a linear fashion.
2. Associative Array – When the array is indexed with strings it is called an associative array.
3. Multidimensional Array the array that has more than one or arrays containing in it is called multidimensional array and it is accessed by using its indices.

Latest News

Add to your IT skills with short term and Professional courses from TOPS with Live Projects in Basic and Advance technologies.

Get Effective PHP Training for Better Career Growth

June 23, 2017

PHP training is essential for anyone in the developing industry. It is one of the best courses that one can go for making better career plans. It helps you in understanding the various database functional specifications. What you can achieve with effective PHP courses? With PHP courses, you can learn the way PHP supports for […]

Get PHP Training and Acquire Top Paying Job in IT

September 28, 2016

PHP is the most easy to grasp programming language. It is also known as the powerful scripting language using which the programmers can develop user friendly websites and applications. Developed by RasmusLerdorf in 1995, PHP has become extremely popular and is being used world-wide because it supports almost all operating systems like Linux, Mac, Windows […]

Training in PHP, PHP Training

March 25, 2016

Why Training? Training is the process of learning the skills you need to do a particular job or activity. Especially in IT field training is required as in IT you are learning a technology where you need to work practically by using the technology to learn it in an effective manner. There is always something […]

Need More Information about Jobs and Training?

Get the Answers you needs in 60 seconds or less

We will call you and answer your queries about Job Opportunities, Free Training and Internship Opportunities, References of students from your college we have placed. Just Fill the information and get the answers in 60 seconds or less.