10 Important PHP Interview Questions

Php Interview Questions

Do you have a PHP interview coming up? Here are 10 PHP interview questions you must know.

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 Source: PHP Official Website.

1. What are the major differences between PHP and Java?

Criteria PHP Java
Deployment area Server-side scripting. General-purpose programming.
Language type Dynamic typed. Static typed.
Rich set of APIs No. Yes.

2. What Are PHP traits?

PHP interview questions are incomplete without PHP traits. A PHP trait is a mechanism for code reusability in a single inheritance language such as PHP. A trait’s structure is the same as a regular PHP code; it’s just a bunch of reusable functions. Despite having the same name, all of the reusable functions have a separate declaration. PHP traits are created by clustering these functions. The class will use the trait attribute to incorporate the functions outlined in it.

3. What is Extract() used for in PHP?

The extract() function imports variables into the local symbol table from an array. It uses variable names as the array keys and variable values for the array values. For every item in the array, it creates a variable within the same symbol table. The syntax is as follows:
extract(array,extract_rules,prefix)

4. What are the types of runtime errors in PHP?

The most common types of runtime errors in PHP are:

  • Notices: These include non-critical trivial errors. By default, they are not displayed to the user.
    Accessing a variable that has not yet been outlined is an example of a notice.
  • Warnings: By default, these errors are visible to the user. They do not lead to script termination.
    Calling an external file that does not exist is a warning.
  • Fatal Errors: These errors cause immediate termination of the script, and PHP’s default behavior is to show them to the user. Instantiating an object of a non-existent class is a fatal error.

5. What Is PDO in PHP?

PDO represents a connection between PHP and a database server.

  • It is a group of PHP extensions that give a core PDO class and database-specific drivers.
  • It provides a vendor-neutral, lightweight, data-access abstraction layer. Thus, irrespective of the database used, the function to issue queries and fetch data will be the same.
  • It focuses on data-access abstraction rather than database abstraction.
  • PDO needs familiarized options within the core of PHP 5. Hence, it’ll not run with earlier versions of PHP.

PDO is divided into two components:

  • The core that provides the interface.
  • Drivers to access the database server.

6. How do you get information about the uploaded file in the receiving script?

Once the web application server receives the file after uploading, it calls the PHP script for processing.

This receiving PHP script will get the data of the uploaded file in a predefined array known as $_FILES. PHP arranges the data present in $_FILES as a two-dimensional array. The retrieval mechanism is as follows:

  1. $_FILES[$fieldName][‘name’] – It represents the file name on the browser system.
  2. $_FILES[$fieldName][‘size’] – It represents the size of the file in bytes.
  3. $_FILES[$fieldName][‘tmp_name’] – This array item provides the temporary computer file name of the uploaded file.
  4. $_FILES[$fieldName][‘error’] – It returns the error code, if any, related to the file transfer.

7. What is the difference between Split And Explode functions for string manipulation in PHP?

Both of them perform the task of extracting a string. However, the mechanism they use is different.
The split() function splits the string into an array by using a regular expression. An example is:
split(:May:June: July);
It returns an array that contains May, June, July.

The explode() function splits the string using a string delimiter. An example is:
explode (and May and June and July);
It returns an array that contains May, June, July.

8. What is PEAR in PHP?

PEAR stands for “PHP Extension and Application Repository”. PEAR is the next revolution in PHP. PEAR is used to automatically install “packages” and can be used as a framework and distribution system for reusable PHP components. The purpose of PEAR is to provide:

  • PHP users a structured library of open-sourced code.
  • A system for code distribution and package maintenance.
  • PHP Foundation categories (PFC).
  • PHP Extension Community Library (PECL).

9. Which library is used for PDF manipulation in PHP?

PHP Interview Questions generally contain something on PDF. The PDF functions in PHP can be accessed using PDFlib library Version 6. PDFlib offers an object-oriented API for PHP 5 in addition to the function-oriented API for PHP 4.
FPDF is a PHP class that permits the generation of PDF files with pure PHP (without using the PDFlib library).
F in ‘FPDF’ means ‘free’; you can use it as and when you need it. You can also modify it if required. FPDF does not need an extension to work with PHP4 and PHP5.

10. How do you avoid an email sent through PHP from landing into the spam folder?

There’s no special method of keeping your emails away from the ‘spam’ label. One should still know about certain pitfalls due to which an email sent via PHP may be labeled as spam. Sending mail using the ‘mail’ function with minimum parameters.

  • Use all possible mail headers like MIME-version, Content-type, Reply address, From address, etc. This makes the email look genuine.
  • Not employing a correct SMTP mail script like PHPmailer or SwiftMailer increases the possibility of the email being categorized as spam mail.

If you send the e-mail from an actual e-mail account using an SMTP mailer script (with username and password), the probability of your email being discarded as spam is reduced.
If you’re on a shared web server, consider buying a unique IP address for yourself. Others using your IP may have gotten it blacklisted for spam. Do not send more than 250 emails to a supplier per hour. Give your users an unsubscribe link.  Moreover, if the e-mail does not render properly, it will be marked as a spam email.

If you feel there are some important PHP interview questions that candidates need to know, we’d love to hear from you. And do mention PHP certifications or PHP tips and tricks you are aware of.

Related Articles

Responses

Wait! Give yourself a chance 😃

50 Proven Interview Keywords to integrate into your interview answers.

Yes, I want those 50 keywords!

“Your words during an interview convey an impression of you and your abilities. Make it a positive one.”