PHP interview questions

A question from Yahoo! Answers:

Where can i get php interview questions along with answers (faqs)?

The quickest way to test an applicant is to discuss differences in object models between PHP 4 and PHP 5:

http://www.php.net/oop
http://www.php.net/oop5

Specific questions may include:

How are class constructors named in PHP 4 (constructor has the same name as class within which it is defined) and PHP 5 (__construct())?

How are class destructors named in PHP 4 (they’re not; PHP 4 has no concept of a destructor) and PHP 5 (__destruct())?

Can you declare a property or method as public, private, or protected in PHP? (Yes, but only in PHP 5; PHP 4 does not support these definitions, so all methods and properties are public.)

In PHP 5, what happens if you don’t declare a property or method as public, private, or protected? (Nothing; unless otherwise declared, a property or method is assumed to be public.)

Can you declare a property or method as static? (Yes, but only in PHP 5.)

Can you define class constants in PHP? (Yes, but only in PHP 5.)

What is an abstract class? (You cannot create an instance of a class that has been defined as abstract.) Can you define an abstract class in PHP? (Yes, but only in PHP 5.)

What is an abstract method? (Methods defined as abstract only declare the method’s signature; they cannot define the implementation.) Can you define an abstract method in PHP? (Yes, but only in PHP 5.) Can you create an instance of class containing an abstract method? (No; declaring a method as abstract automatically renders the containing class abstract.)

What are final methods? (They cannot be redefined by child classes.) Can you define a method as final in PHP? (Yes, but only in PHP 5.)

What are final classes? (They cannot be extended.) Can you define a class as final in PHP? (Yes, but only in PHP 5.)

Can you use type hinting in PHP? (Yes, but only in PHP 5.)

This entry was posted in Answers, Technology. Bookmark the permalink.

Leave a Reply

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