PHP interview questions with answers

Hello there, In this tutorial i have given set of php interview question and answers. Included are php, mysql, javascript, html, css, jquery.

1.What is PHP?

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

2.Who is the father of PHP?

Rasmus Lerdorf.

The PHP Group consists of ten people (as of 2015 ): Thies C. Arntzen, Stig Bakken, Shane Caraveo, Andi Gutmans, Rasmus Lerdorf, Sam Ruby, Sascha Schumann, Zeev Suraski, Jim Winstead, Andrei Zmievski.

3.What are the common usage of PHP?

Common uses of PHP −

  • PHP performs system functions, i.e. from files on a system it can create, open, read, write, and close them.
  • PHP can handle forms, i.e. gather data from files, save data to a file, thru email you can send data, return data to the user.
  • You add, delete, modify elements within your database thru PHP.
  • Access cookies variables and set cookies.
  • Using PHP, you can restrict users to access some pages of your website.
  • It can encrypt data.

4.How to embed PHP Code into html?

<html>

<head>

<title></title>

<body>

<div>

<?php echo “Welcome to Codelab”; ?>

</div>

</body>

</html>

5.What is php.ini?

php.ini is a configuration file.this is read when php starts.For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.

The php.ini file is where you declare changes to your PHP settings. You can use the default settings for the server, change specific settings by editing the existing php.ini, or create a new text file and name it php.ini.

6.What is naming convention?

Naming convention is a convention set of rules for choosing the character sequence to be used for identifiers which denote variables, types, functions, and other entities in source code and documentation.

7.What is case sensitive?

Text or inputted text that is sensitive to capitalization of letters.For example, “Computer” and “computer” are two different words because the “C” is uppercase in the first example and lowercase in the second example.In many cases with computers or accounts that require a logon to access, the username and password is case-sensitive, which means the username and password must have the correct case.

In computers, some examples of usually case-sensitive data are:

1.username
2.password
3.filenames
4.tags
5.commands
6.variable names
7.text string searches within electronic text

8.Is PHP function names case-sensitive or not?

No . PHP is case insensitive.

Function names are case-insensitive, though it is usually good form to call functions as they appear in their declaration.

9.What are the characteristics of PHP variables?

Here are the most important things to know about variables in PHP.

  • All variables in PHP are denoted with a leading dollar sign ($).
  • The value of a variable is the value of its most recent assignment.
  • Variables are assigned with the = operator, with the variable on the left-hand side and the expression to be evaluated on the right.
  • Variables can, but do not need, to be declared before assignment.
  • Variables in PHP do not have intrinsic types – a variable does not know in advance whether it will be used to store a number or a string of characters.
  • Variables used before they are assigned have default values.
  • PHP does a good job of automatically converting types from one to another when necessary.
  • PHP variables are Perl-like.

10.What are rules for naming a PHP variable?

Rules for naming a variable are following −

  • 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

11.What is NULL?

It is a special type. it will have only one value NULL.To give a variable the NULL value, simply assign it like this −

12.What is constant and how to define PHP constant?

Constant is an identifier for a simple value.The value cannot be changed during the script.A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constantsare automatically global across the entire script.

<?php define(“PRABA”, 1);

echo PRABA;

?>

13.What are the different types of errors in php?

  • E_ERROR: A fatal error that causes script termination
  • E_WARNING: Run-time warning that does not cause script termination
  • E_PARSE: Compile time parse error.
  • E_NOTICE: Run time notice caused due to error in code
  • E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
  • E_CORE_WARNING: Warnings that occur during PHP’s initial startup
  • E_COMPILE_ERROR: Fatal compile-time errors indication problem with 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_DEPRECATED:Run-time notices.
  • E_USER_DEPRECATED:User-generated warning message. This is like an E_DEPRECATED, except it is generated in PHP code by using the PHP function trigger_error().
  • E_ALL: Catches all errors and warnings

14.What is nl2br?

Insert line breaks where newlines (\n) occur in the string:

<?php
echo nl2br(“Prabhs.\ncodelab”);
?>

output:

Prabhs

codelab
15.What is an array?

Collection data types comes under common variable.

The array() function is used to create an array. In PHP, there are three types ofarrays: Indexed arraysArrays with numeric index. Associative arraysArrayswith named keys
16.What is string?

String is sequence of characters.
17.How to concatenate two variables in php?

 

We can concatenate two variables using “.” operator.

<?php

$var1 = 1;

$var2 = 2;

echo $var1.$var2;

?>
18.What is cookies?

Cookies are used to store the information on client side(local system).

A cookie is created with the setcookie() function.

syntax: setcookie(name, value, expire, path, domain, secure, httponly);

19.What is session?

Sessions are used to store the information server end.

a session is created with the session_start() function

<?php session_start(); ?>

20.How will you access uploaded file?

Using $_FILES[‘file’][‘tmp_name’] − it provides access to the uploaded file in the temporary directory on the web server.

Updated: December 3, 2016 — 2:33 pm

Leave a Reply

Your email address will not be published.

prabaweb.in Codelab- programming blog © 2017