PHP Interview Questions

PHP Interview Questions and Answers

Below is the list of latest and updated PHP interview questions and their answers for fresher’s as well as experienced users.  The combination of PHP and MySQL is the most convenient approach to dynamic, database-driven web design, holding its own in the face of challenges from integrated Frameworks.

Best PHP Interview Questions and Answers

Many of these development environments let you run the PHP code and see the out‐ put discussed in this chapter. I’ll also show you how to embed the PHP in an HTML file so that you can see what the output looks like in a web page. Below list of PHP interview Questions will help to understand the PHP for beginners before attend the interview.

What’s PHP?

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software  applications.


What is meant by PEAR in php?

PEAR is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install “packages”

What Is a Persistent Cookie?

A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased.

What is meant by urlencode and urldecode?

urlencode() returns the URL encoded version of the given string. URL coding converts special characters into % signs followed by two hex digits. For example: urlencode(“10.00%”) will return “10%2E00%25”. URL encoded strings are safe to be used as part of URLs. urldecode() returns the URL decoded version of the given string.

What is the difference between mysql_fetch_object and mysql_fetch_array?

MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array.

How can I execute a PHP script using command line?

Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, “php myScript.php”, assuming “php” is the command to invoke the CLI program. Be aware that if your PHP script was written for the Web CGI interface, it may not execute properly in command line environment.

I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?

PHP Interpreter treats numbers beginning with 0 as octal. Look at the similar PHP interview questions for more numeric problems.

What is the functionality of the functions STRSTR() and STRISTR()?

string strstr ( string haystack, string needle ) returns part of haystack string from the first occurrence of needle to the end of haystack. This function is case-sensitive. stristr() is idential to strstr() except that it is case insensitive.

When are you supposed to use endif to end the conditional statement?

When the original if was followed by: and then the code block without braces.

How can we send mail using JavaScript?

No. There is no way to send emails directly using JavaScript.

What Are the different Types of Errors in PHP?

Here are three basic types of runtime errors in PHP:

  1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script – for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all – although you can change this default behaviour.
  1. Warnings: These are more serious errors – for example, attempting to include () a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
  2. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behaviour is to display them to the user when they take place.

What is the difference between the functions unlink and unset?

unlink() is a function for file system handling. It will simply delete the file in context. unset() is a function for variable management. It will make a variable undefined.

How come the code works, but doesn’t for two-dimensional array of mine?

Any time you have an array with more than one dimension, complex parsing syntax is required. print “Contents: {$arr[1][2]}” would’ve worked.

How can we submit form without a submit button?

We can use a simple JavaScript code linked to an event trigger of any form field. In the JavaScript code, we can call the document.form.submit() function to submit the form.

For example:

<input type=button value="Save" onClick="document.form.submit()">

How can we create a database using PHP and mysql?

We can create MySQL database with the use of mysql_create_db($databaseName) to create a database.

How many ways we can retrieve the date in result set of mysql using php?

As individual objects so single record or as a set or arrays.

Can we use include (“abc.php”) two times in a php page “makeit.php”?

Yes.

What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128-bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

What is meant by MIME?

MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However, browsers also uses MIME standard to transmit files. MIME has a header which is added to beginning of the data. When browser sees such header it shows the data as it would be a file (for example image)

Some examples of MIME types:

audio/x-ms-wmp
image/png
application/x-shockwave-flash

Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?

Yes we can include that many times we want, but here are some things to make sure of: (including abc.PHP, the file names are case-sensitive) there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

What is the use of friend function?

A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.

What are the difference between abstract class and interface?

Abstract class: abstract classes are the class where one or more methods are abstract but not necessarily all method has to be abstract. Abstract methods are the methods, which are declare in its class but not define. The definition of those methods must be in its extending class.

What is maximum size of a database in mysql?

If the operating system or filesystem places a limit on the number of files in a directory, MySQL is bound by that constraint. The efficiency of the operating system in handling large numbers of files in directory can place a practical limit on the number of tables in a database.

What type of inheritance that php supports?

In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword ‘extends’.

How can increase the performance of MySQL select query?

We can use LIMIT to stop MySql for further search in table after we have received our required no. of records, also we can use LEFT JOIN or RIGHT JOIN instead of full join in cases we have related data in two or more tables.

Then, with PHP under your belt, you will move on to an introduction to the MySQL database system, where you will learn everything from how MySQL databases are structured to how to generate complex queries.

Thus, the compilation of these questions includes some of the major points that can be asked during an interview. The Fortran interviewers generally check the base knowledge of a candidate, which can be gained by practicing these questions prior interview.

So if you have finally found your dream job in PHP Developer/Or coder but are wondering how to crack the PHP Interview and what could be the probable PHP Interview Questions. Every interview is different and the scope of a job is different too. Hope above assist you to get a dream PHP Job. Keep Learn.

Online Training Tutorials

  • XML Interview QuestionsXML Interview Questions and AnswersBelow is the list of latest and updated XML interview questions and their answers for fresher’s as well as experienced users. These interview question covers basic and latest version of […]
  • VBScript Interview Questions and AnswersVBScript Interview Questions and AnswersVBScript is a powerful but easy-to learn scripting language that you can use to perform a number of useful activities, including enhancing your web pages and automating repetitive or […]
  • Siebel Interview Questions and AnswersSiebel Interview Questions and AnswersSiebel is a CRM (Customer Relationship Management) application. It is mainly deployed by companies which have huge customer base and expect regular interaction with them. There are other […]
  • Ruby Interview QuestionsRuby Interview Questions and AnswersProgramming Ruby is known to Rubyists. It is a tutorial and reference for the Ruby programming language. Before we start talking about the Ruby language, it’d be useful if we helped you […]
  • OOP Interview Questions and AnswersOOP Interview Questions and AnswersThere are still people, for instance, that call Artificial Intelligence to any program that is written in Prolog or Lisp. In the same way, there are those who maintain that any program […]
  • OOAD Interview QuestionsOOAD Interview Questions and AnswersOOAD -Object-Oriented Design: The emphasis in programming methods is primarily on the proper and effective use of particular language mechanisms. By contrast, design methods emphasize the […]
  • MySQL Interview Questions and AnswersMySQL Interview Questions and AnswersMySQL is a relatively recent entrant into the well-established area of relational database management systems (RDBMs), a concept invented by IBM researcher Edgar Frank Codd in 1970. […]
  • JavaScript Interview Questions and AnswersJavaScript Interview Questions and AnswersJavascript is an interpreted language with a C like syntax. While many people brush the language off as nothing more than a browser scripting language, it actually supports many advanced […]