You might be writing code for a long time but when it comes to the theory you feel stuck?
Then you have come to the right place. Let’s learn interview questions asked and crack the theory part. You are already good at programming part. Yes, you are!!! every programmer is. Let’s crack it now.
Learn Basic PHP interview question

What do you know about PHP?

PHP is a scripting language that is mainly used to create dynamic web pages. PHP code can be embedded to HTML to create a dynamic web page. PHP originally stood for Personal Home Page, but it now stands for the recursive acronym PHP: Hypertext Preprocessor.

What do you understand by PEAR in PHP?

PEAR stands for “PHP Extension and Application Repository”. A structured library of open-source code for PHP users. It is a framework for reusable PHP components.

Is it possible to execute PHP script from the command line? How?

Yes it is possible just open command line interface and use

php scriptname.php 

Make sure to include php in environment variable.

When will we use require() and include() function in PHP

Require and include both functions are used for including an external file but in case of require if we do not include the file it will give a fatal error and stop the execution of programme, however, include will not give the fatal error and do not stop the execution of the program.

What is the difference between require_once() and require() ?

require(), and require_once() both are used to include other PHP file. require _once function check if the file is already included if it is included it will not include that again

How we can change the execution time in PHP script?

We can define a function set_time_limit(int $seconds ) to limit the maximum execution time.The default limit is 30 sec.max_execution_time value defined in the php.ini.

What PHP function is used for reading a file?

file_get_contents()

How we can get the number of rows returned in the result set?

mysqli_num_rows()

PHP function to check if the value of a variable is number or variable?

is_numeric().

How to check if a variable is empty ?

empty()

What is difference between unlink() and unset() function?

Unset() function will make a variable undefined.
unlink() function is used in file handling system and it deletes the file.

How can we remove HTML tags from data?

strip_tags() is used to remove HTML tags

What is the difference between session and cookie in PHP?

Cookie data is stored on visitor browser whereas session data is stored on the server. Session data is lost as soon as we close the browser however cookie is stored in the user browser until its expiry time or until user deleted the cookie from the browser.

How we can initiate a session in PHP?

session_start() functions used to start session in PHP

How we can get the list of all global variables?

$GLOBALS we can use to get all variables defined in the global scope

What does $_SERVER used for in PHP?

$_SERVER is an array that includes information like paths, headers, and script locations.

What does $_FILES means?

$_FILES is an associative array composed of items sent to the current script via the HTTP POST method.

What is default maximum upload size of an image? Is it possible to change that?

Default size to upload an image is 2MB. It is possible to change the max upload size by editing php.ini file upload_max_filesize

What is the difference between ‘==’ and ‘===’

== check just value === check value as well as datatype

What are different types of error occur in PHP?

1) notices (non-critical),
2)warnings (serious)
3) fatal errors (critical). -> Stops the execution of programme

What are different ways to pass a variable between pages in PHP?

1)Sessions
2)Cookies
3)Hidden form fields.

How can we insert the new line in PHP

echo “Hello World”. “\n”

PHP variable that contains all web server information

$_SERVER

What is the use of htmlspecialchars() in PHP?

Make sure any characters that are special in HTML are properly encoded so people can’t inject HTML tags or Javascript into your page.

Give some example of superglobal variable in PHP

$_GET, $_POST, $_COOKIE, $_SERVER, $_FILES, $_ENV, $_REQUEST, and $_SESSION

Which function is used to check the type and value of an expression, use

var_dump()

Syntax to show all errors

error_reporting(E_ALL);

How can we redirect a page in PHP?

header(“Location: login.php”);

What is the use id ob_start() and ob_end_flush()

Ob_start starts out the buffering
Ob_end_flush ends the buffering and flushes whatever result have accumulated to web server

Get the ip address

$_SERVER[‘REMOTE_ADDR’]

Basic PHP Interview Questions

Leave a Reply

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