Hire a PHP Developerdevelopment 15 PHP INTERVIEW QUESTIONS

15 PHP INTERVIEW QUESTIONS

What’s the difference between the include() and require() functions?

While both functions have a specific file, there is a fatal error on  require() if the file is not included. On the other hand, the include statement only proceeds to the next step of the execution.

How can we get the client’s IP address?

What’s the difference between  unset() and unlink()

unlink()  performs the function of deleting a file passed on to it  from the file system while unset() sets a variable to “undefined”

Provide an answer for the output of the code below:

The answer is 21, 21

Name the main error types in PHP

Notices: these are simple errors that occur during script execution. This would occur when you access an undefined variable.

Warnings: this is a bigger error than notices. However, it does not stop the script execution.

Fatal: if this type of error occurs, it causes a termination to the script execution.  This would happen if one tried to access the property of a nonexistent file.

How can you enable error reporting in PHP?

You have to check whether “display_errors” is equal “on” in the php.ini, or you may declare “ini_set(‘display_errors’, 1)” in your script. After that, include  error_reporting(E_ALL)” in your code which will display all error messages that occurred during script execution.

Define traits

They are a mechanism that allows a developer to create reusable code in languages like PHP which do not allow multiple inheritance.

Can the value of a constant change during the script’s execution?

Once it has been declared during a PHP execution, it would be impossible to change the value of a constant.

Is it possible to extend a Final defined class?

No, it is not possible. A Final class prevents child class and method overriding.

Name the  __construct() and  __destruct() methods in a PHP class

Objects in PHP have inbuilt Constructor and Destructor methods. The Constructor method is used immediately after the creation of a new instance of the class and it initializes class properties. There are no parameters taken in Destructor.

How can we get the number of elements in an array?   

By using the count() function. It is used to return the number of elements in an array.

How would you declare a function that receives one parameter name hello?

The function must print hello if indeed hello is true. But if the function fails to receive hello or hello is false then the function must print bye.

 

What if you receive a form submitted by a post to subscribe to a newsletter. This form has a single field, an input text field named email. How would you validate whether the field is empty? Print a message “The email cannot be empty” in this case.

 

Define the 3 scope levels found in PHP

Private – this is visible only in its own class

Public – Visible to any other code accessing the class

Protected – Visible only to classes parent(s) and classes that extend the current class

What is the output of the following code?

The output is 7. The first zero is indicative of an octal number in PHP. This means that the number evaluates to the decimal number 14 instead of 16.

 

No Comments

Leave a reply