Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which method is invoked when an undefined property is accessed?(a) __get()(b) __isset()(c) __unset()(d) __undefined()I had been asked this question in a national level competition.Question is taken from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer» RIGHT CHOICE is (a) __get()

EXPLANATION: NONE.
2.

__clone() is run on the ___ object.(a) original(b) pseudo(c) external(d) copiedThis question was posed to me in final exam.My doubt stems from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer»

Right option is (d) COPIED

Easiest explanation: __clone() is run on the copied OBJECT and not the original.

3.

Which keyword must be added before $first variable on the third line of the above question to make $second and $first as distinct objects in PHP 5?(a) copy(b) clone(c) cut(d) Can’t add any word to make them distinctI have been asked this question by my school principal while I was bunking the class.I'm obligated to ask this question of Object Advanced Features in portion Objects and Databases in PHP of PHP

Answer» RIGHT ANSWER is (B) clone

To elaborate: Clone operates on an object instance, PRODUCING a by-value COPY.
4.

Which method introduced in PHP 5, is invoked just before an object is a garbage collected?(a) __collect()(b) __garbage()(c) __destruct()(d) __destructor()I got this question during an online exam.I'm obligated to ask this question of Object Advanced Features topic in division Objects and Databases in PHP of PHP

Answer» CORRECT ANSWER is (c) __destruct()

To explain: You can use this method to perform any final cleaning up that might be necessary. Imagine, for example, a class that saves itself to a database when so ordered. I could use the __destruct() method to ENSURE that an instance saves its DATA when it is deleted.
5.

Which one of the following method is invoked when an undefined method is called by client code?(a) __get()(b) __isset()(c) __unset()(d) __call()The question was asked during a job interview.This question is from Object Advanced Features in section Objects and Databases in PHP of PHP

Answer»

The correct option is (d) __call()

Explanation: The __call() METHOD is probably the most USEFUL of all the INTERCEPTOR methods. The __call() method can be useful for delegation. Delegation is the mechanism by which one object PASSES method invocations on to a second.

6.

Which one of the following method is invoked when a value is assigned to an undefined property?(a) __get()(b) __set()(c) __isset()(d) __call()This question was addressed to me in class test.My question is from Object Advanced Features in section Objects and Databases in PHP of PHP

Answer»

Correct ANSWER is (b) __set()

Best explanation: The __set() method is INVOKED when client code attempts to assign to an undefined property. It is PASSED TWO arguments: the name of the property, and the value the client is attempting to set.

7.

PHP provides built-in interceptor methods, which can intercept messages sent to undefined methods and properties. This is also known as _________(a) overloading(b) overriding(c) overbending(d) overbindingThe question was posed to me by my college professor while I was bunking the class.My doubt stems from Object Advanced Features topic in portion Objects and Databases in PHP of PHP

Answer»

The CORRECT ANSWER is (a) overloading

For EXPLANATION: NONE.

8.

Which one of the following keyword is used in conjunction with an Exception object?(a) throws(b) exception(c) throw(d) finalThis question was posed to me in an interview for job.My query is from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer» RIGHT choice is (c) throw

For explanation I would say: The throw keyword is used in CONJUNCTION with an Exception object. It halts the execution of the current method and PASSES responsibility for handling the ERROR BACK to the calling code.
9.

Which keyword is used to put a stop on inheritance?(a) stop(b) end(c) break(d) finalI have been asked this question by my college director while I was bunking the class.I want to ask this question from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer» RIGHT OPTION is (d) FINAL

Explanation: A final CLASS cannot be subclassed.
10.

Which one of the following methods in the exception class, is used to get a nested exception object?(a) getPrevious()(b) getCode()(c) getFile()(d) getLine()This question was posed to me during an interview for a job.Origin of the question is Object Advanced Features in section Objects and Databases in PHP of PHP

Answer»

Right option is (a) GETPREVIOUS()

The explanation: getCode() – GET the CODE integer that was PASSED to the constructor. getFile() – Get the file in which the EXCEPTION was generated. getLine() – Get the line number at which the exception was generated.

11.

Which version of PHP introduced the concept called late static binding?(a) PHP 4(b) PHP 5(c) PHP 5.1(d) PHP 5.3I have been asked this question in quiz.I'm obligated to ask this question of Object Advanced Features in chapter Objects and Databases in PHP of PHP

Answer» CORRECT OPTION is (d) PHP 5.3

Explanation: NONE.
12.

Which one of the following keyword is used to implement an interface?(a) interface(b) get(c) inherit(d) implementsThis question was posed to me by my school teacher while I was bunking the class.I need to ask this question from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer»

The CORRECT choice is (d) implements

The explanation is: A class can IMPLEMENT an interface USING the implements keyword in its declaration.

13.

At least how many abstract methods must an abstract class contain?(a) None(b) One(c) Two(d) FiveI have been asked this question in a national level competition.Enquiry is from Object Advanced Features in portion Objects and Databases in PHP of PHP

Answer»

The correct option is (B) One

The EXPLANATION is: Classes DEFINED as abstract may not be instantiated, and any class that contains at least one abstract method must also be abstract.

14.

Which one of the following keywords are used to define an abstract class?(a) extends(b) implements(c) abstract(d) newThe question was posed to me in an international level competition.Question is taken from Object Advanced Features in division Objects and Databases in PHP of PHP

Answer»

Right CHOICE is (c) abstract

Explanation: The introduction of abstract classes was ONE of the major changes USHERED in with PHP 5. Its inclusion in the list of new features was ANOTHER sign of PHP’s extended commitment to object-oriented DESIGN.

15.

Which one of the following class can not be instantiated?(a) inherited class(b) abstract class(c) constant class(d) every classThe question was posed to me in an interview for internship.My question comes from Object Advanced Features topic in portion Objects and Databases in PHP of PHP

Answer»

Correct choice is (B) abstract class

To elaborate: An abstract class cannot be INSTANTIATED. INSTEAD, it defines (and, optionally, PARTIALLY implements) the interface for any class that might extend it.

16.

Which one of the following is the correct abstract method?(a) public function write()(b) abstract function write()(c) abstract public write();(d) abstract public function write();I have been asked this question in an interview.I'm obligated to ask this question of Object Advanced Features in chapter Objects and Databases in PHP of PHP

Answer»

The correct CHOICE is (d) abstract PUBLIC function write();

The explanation: An abstract method cannot have an implementation. You DECLARE it in the normal way, but end the DECLARATION with a semicolon RATHER than a method body.

17.

What will happen if you try to set a value to a constant once it has been declared?(a) The value of the variable will change(b) The value of the variable will not change(c) Parse Error(d) NothingI got this question during an online exam.The origin of the question is Object Advanced Features in chapter Objects and Databases in PHP of PHP

Answer»

Right OPTION is (c) PARSE Error

For explanation: You should use constants when your property NEEDS to be available across all instances of a CLASS, and when the property VALUE needs to be fixed and unchanging.

18.

Which one of the following is a constant variable?(a) const $name(b) const $NAME(c) constant NAME(d) const NAMEThe question was posed to me in unit test.Origin of the question is Object Advanced Features in section Objects and Databases in PHP of PHP

Answer»

The correct CHOICE is (d) const NAME

For explanation I WOULD say: Constants are not prefixed with a dollar sign like regular properties. By convention, they are OFTEN NAMED using only UPPERCASE characters

19.

Which keyword is used to declare a constant property?(a) const(b) con(c) constant(d) _constantThe question was asked in an international level competition.My question comes from Object Advanced Features topic in chapter Objects and Databases in PHP of PHP

Answer»

Right option is (a) const

Easiest EXPLANATION: A constant PROPERTY is declared with the const KEYWORD. Like global constants, class constants cannot be CHANGED once they are set.

20.

Which version of PHP allows you to define constant properties within a class?(a) PHP 4(b) PHP 4.1(c) PHP 4.3(d) PHP 5The question was posed to me during a job interview.Origin of the question is Object Advanced Features topic in division Objects and Databases in PHP of PHP

Answer» CORRECT CHOICE is (d) PHP 5

The BEST I can EXPLAIN: None.
21.

What does PDO stand for?(a) PHP Data Orientation(b) PHP Database Object(c) PHP Database Orientation(d) PHP Data ObjectThis question was addressed to me during a job interview.The origin of the question is Object Advanced Features topic in division Objects and Databases in PHP of PHP

Answer»

The correct option is (d) PHP DATA Object

Easy explanation: The PDO class provides a COMMON INTERFACE to different database APPLICATIONS.

22.

Which one of the following variable cannot be used inside a static method?(a) $this(b) $get(c) $set(d) $dateThis question was posed to me in quiz.My doubt is from Object Advanced Features in chapter Objects and Databases in PHP of PHP

Answer»

The correct choice is (a) $this

The explanation: By definition, static methods are not invoked in the CONTEXT of an object. For this reason, static methods and properties are often REFERRED to as CLASS variables and properties.

23.

In which of the following circumstance should you use a static reference to a non static method?(a) Making a method call using parent(b) Making a method call using child(c) Making an object call using parent(d) Making an object call using childThis question was addressed to me in my homework.This intriguing question comes from Object Advanced Features in portion Objects and Databases in PHP of PHP

Answer»

Correct choice is (a) Making a METHOD CALL using PARENT

Easy explanation: Making a method call using parent is the only circumstance in which you should use a STATIC reference to a non-static method.

24.

Which keyword is used to access a static method or property from within the same class(rather than from child)?(a) static(b) strat(c) self(d) setThis question was addressed to me in semester exam.I want to ask this question from Object Advanced Features topic in section Objects and Databases in PHP of PHP

Answer»

The correct CHOICE is (c) SELF

The EXPLANATION is: Self is to CLASSES what the $this pseudo-variable is to objects.

25.

Which one of the following is true about the following line – $obj = new ImageHandler(‘/images/’, array(400, 300));?(a) This snippet sets the maximum dimensions allowed to 400 pixels wide by 300 pixels high(b) This snippet sets the minimum dimensions allowed to 300 pixels wide by 400 pixels high(c) This snippet sets the minimum dimensions allowed to 400 pixels wide by 300 pixels high(d) This snippet sets the maximum dimensions allowed to 300 pixels wide by 400 pixels highThe question was posed to me by my school principal while I was bunking the class.My question is taken from Image Uploading Ability topic in portion Objects and Databases in PHP of PHP

Answer»

The correct answer is (a) This snippet sets the MAXIMUM dimensions allowed to 400 PIXELS WIDE by 300 pixels high

The explanation is: If you needed to change the size of your images, you can change the dimensions using the above INSTANTIATION of ImageHandler.

26.

Which version of PHP introduced the static keyword?(a) PHP 4(b) PHP 5(c) PHP 5.2(d) PHP 5.3This question was addressed to me in an interview.I need to ask this question from Object Advanced Features topic in section Objects and Databases in PHP of PHP

Answer» CORRECT option is (b) PHP 5

The BEST I can EXPLAIN: The static keyword was introduced with PHP 5. It cannot be used in PHP 4 scripts.
27.

Which function do you have to use to check whether the $path you’ve stored exists?(a) path_dir()(b) path()(c) is_dir()(d) path_dir()This question was addressed to me by my college professor while I was bunking the class.This interesting question is from Image Uploading Ability topic in division Objects and Databases in PHP of PHP

Answer»

Right answer is (c) is_dir()

The explanation is: If the path exists, is_dir() RETURNS TRUE; OTHERWISE, it returns FALSE.

28.

You use the $_SERVER superglobal and your _______ property to create your path to check.(a) $load_dir(b) $load(c) $save(d) $save_dirI have been asked this question during an online exam.My enquiry is from Image Uploading Ability in section Objects and Databases in PHP of PHP

Answer» RIGHT OPTION is (d) $save_dir

Explanation: // DETERMINES the PATH to CHECK
29.

Before you try to process the file, you need to make sure that your $err value is equivalent to _________(a) UPLOAD_ERR_OK(b) UPLOAD_NO_ERR(c) UPLOAD_ERR_NO_OK(d) UPLOAD_ERRI had been asked this question by my school teacher while I was bunking the class.I'd like to ask this question from Image Uploading Ability topic in chapter Objects and Databases in PHP of PHP

Answer»

Correct OPTION is (a) UPLOAD_ERR_OK

The explanation is: When you’re dealing with files uploaded through an HTML form, you have access to a SPECIAL CONSTANT CALLED UPLOAD_ERR_OK that TELLS you whether a file uploaded successfully.

30.

To process the file, you need to break the array from $_FILES into individual values. You can do this using the ________ function.(a) divide()(b) list()(c) break()(d) indi()This question was addressed to me in an online quiz.I want to ask this question from Image Uploading Ability in division Objects and Databases in PHP of PHP

Answer»

Correct CHOICE is (b) LIST()

The explanation is: The list() function ALLOWS you to CREATE named VARIABLES for each array index as a comma-separated list.

31.

DocBlocks are indicated by opening a comment using _________(a) /*(b) //*(c) /**(d) /*/The question was asked during an interview for a job.I'd like to ask this question from Image Uploading Ability in portion Objects and Databases in PHP of PHP

Answer»

The correct ANSWER is (c) /**

The BEST I can EXPLAIN: This is a special comment that PROVIDES information about a class, property, or method.

32.

To make the ImageHandler class portable you should create a separate file for it called __________(a) imagehandler.inc.php(b) images.inc.php(c) handler.inc.php(d) imghandler.inc.phpThe question was asked at a job interview.My question comes from Image Uploading Ability topic in portion Objects and Databases in PHP of PHP

Answer»

The CORRECT ANSWER is (b) images.INC.php

The best I can explain: You SAVE this file in the inc folder (FULL path: /xampp/htdocs/simple_blog/inc/images.inc.php).

33.

To check whether a file was uploaded, you look in the _______ superglobal array.(a) $_FILES(b) $_DOCS(c) $_DOCUMENTS(d) $_FOLDERSI have been asked this question in an internship interview.Enquiry is from Image Uploading Ability topic in portion Objects and Databases in PHP of PHP

Answer»

Right answer is (a) $_FILES

Easiest explanation: Whenever a FILE is uploaded via an HTML form, that file is stored in TEMPORARY memory and INFORMATION about the file is passed in the $_FILES superglobal.

34.

When you’re uploading files you need to set the enctype of the form to __________(a) text(b) text/file(c) multipart/form-data(d) multimedia/form-dataI had been asked this question in an internship interview.My query is from Image Uploading Ability topic in chapter Objects and Databases in PHP of PHP

Answer» RIGHT answer is (C) multipart/FORM-data

Easy explanation: Set the enctype of the form to multipart/form-data, which can ACCEPT files and standard form VALUES.
35.

Before you can start processing images with PHP, you must first add the ability to upload images to your administrative form on ________(a) .htaccess(b) function.inc.php(c) index.php(d) admin.phpThis question was posed to me during an internship interview.My doubt is from Image Uploading Ability topic in chapter Objects and Databases in PHP of PHP

Answer»

Right OPTION is (d) admin.php

Explanation: To do this, you’ NEED to ADD a FILE UPLOAD input to your administrative form.

36.

When a user confirms that he wishes to delete an entry, that entry’s URL is passed to a function which removes the entry from the __________(a) index.php(b) function.inc.php(c) database(d) admin.phpI had been asked this question during an online interview.The question is from Updating and Deleting Entries topic in chapter Objects and Databases in PHP of PHP

Answer»

The correct choice is (c) database

Easiest explanation: If the FUNCTION is successful, you send the user to the main page. If it fails, you stop the execution of the script and DISPLAY an ERROR, LETTING the user know that something went WRONG.

37.

Your confirmation form submits your choice, via the _______ method, to ________(a) GET index.php(b) GET admin.php(c) POST index.php(d) POST admin.phpThis question was posed to me during an online interview.This interesting question is from Updating and Deleting Entries in portion Objects and Databases in PHP of PHP

Answer» CORRECT choice is (d) POST admin.php

Easiest EXPLANATION: To process this, you need to add an ADDITIONAL block of code to the top of admin.php that determines what choices you’ve made and act accordingly.
38.

To declare the function to confirm the deletion you need to add the code to __________(a) inc.php(b) functions.inc.php(c) include.php(d) functions.include.phpI had been asked this question in examination.My question is based upon Updating and Deleting Entries topic in division Objects and Databases in PHP of PHP

Answer»

Right OPTION is (b) functions.inc.php

To explain I would say: You NEED to add the FOLLOWING code –

39.

To identify entries marked for deletion, you check whether $_GET[‘page’] == ‘delete’ inside __________(a) index.php(b) index.ini(c) admin.php(d) .htaccessI have been asked this question in homework.Question is from Updating and Deleting Entries topic in portion Objects and Databases in PHP of PHP

Answer»

The correct choice is (c) admin.php

Explanation: In admin.php, you check WHETHER $_GET[‘page’] == ‘delete’, then PASS the ENTRY URL to be DELETED to a FUNCTION.

40.

You need to check whether ______ is set, to determine whether you’re editing an entry or creating a new one.(a) $_GET[‘url’](b) $_SET[‘url’](c) $_GET[‘admin’](d) $_SET[‘admin’]The question was posed to me during an interview.My question is based upon Updating and Deleting Entries topic in portion Objects and Databases in PHP of PHP

Answer»

Correct CHOICE is (a) $_GET[‘url’]

The EXPLANATION is: If an entry is being EDITED, you need to load the existing entry data and SAVE each piece in a variable.

41.

([\w-]+) will match ___________(a) one word characters(b) one or more word characters(c) one or more word characters and/or hyphens(d) one or more word characters and hyphensThis question was posed to me during an online exam.Query is from Updating and Deleting Entries topic in section Objects and Databases in PHP of PHP

Answer»

Right option is (c) one or more WORD characters and/or hyphens

The explanation: ([\W-]+), will match one or more word characters and/or hyphens—which is what your custom entry URLS CONSIST.

42.

The (|/) tells the server to match ___________(a) nothing(b) forward slash(c) backward slash(d) either nothing or a forward slashI had been asked this question during a job interview.This question is from Updating and Deleting Entries in chapter Objects and Databases in PHP of PHP

Answer»

Right option is (d) either NOTHING or a forward slash

The EXPLANATION: The vertical PIPE CHARACTER (|) is the REGULAR expression equivalent of “or”.

43.

The URLs in the administrative links won’t mean anything to admin.php unless you modify _________(a) .htaccess(b) .adminaccess(c) .htmlaccess(d) .urlaccessThis question was posed to me during an interview.I want to ask this question from Updating and Deleting Entries topic in section Objects and Databases in PHP of PHP

Answer»

Correct OPTION is (a) .htaccess

The best I can EXPLAIN: You need to modify .htaccess with an ADDITIONAL rule that handles URLs PASSED in a link to admin.php.

44.

Once your application can generate administrative links, you need to load those links into _________(a) php.ini(b) index.ini(c) index.php(d) start.phpThis question was addressed to me by my school teacher while I was bunking the class.This intriguing question comes from Updating and Deleting Entries in chapter Objects and Databases in PHP of PHP

Answer»

Right option is (C) index.php

To ELABORATE: You place your administrative LINKS only on the full display of an entry, so you must place the call to load information from adminLinks() WITHIN a conditional statement

45.

When you are building administrative links you’ll need to accept two arguments, which of the following are they?(a) URL of previous entry and URL of the entry you are working with(b) The current page and previous page(c) URL of previous entry and previous page(d) The current page and URL of the entry you are working withThis question was posed to me during an online interview.The origin of the question is Updating and Deleting Entries topic in section Objects and Databases in PHP of PHP

Answer»

The correct CHOICE is (d) The current PAGE and URL of the ENTRY you are working with

Easiest explanation: Your function should look like this:

46.

If you omit the visibility keyword in your method declaration, by default the method will be declared as ____________(a) public(b) private(c) protected(d) friendlyThe question was asked in a job interview.My question comes from Object Basics-1 topic in section Objects and Databases in PHP of PHP

Answer» CORRECT choice is (a) PUBLIC

For explanation I WOULD SAY: By declaring a method public, you ENSURE that it can be invoked from outside of the current object.
47.

Which function is used to determine whether the variable’s value is either TRUE or FALSE?(a) boolean()(b) is_boolean()(c) bool()(d) is_bool()The question was posed to me during an interview for a job.The origin of the question is Object Basics-1 in chapter Objects and Databases in PHP of PHP

Answer»

The CORRECT ANSWER is (d) is_bool()

BEST EXPLANATION: NONE.

48.

Which keyword precedes a method name?(a) method(b) function(c) public(d) protectedI had been asked this question in my homework.My question is based upon Object Basics-1 topic in division Objects and Databases in PHP of PHP

Answer» RIGHT option is (b) function

The explanation is: A METHOD declaration resembles a function declaration. The function KEYWORD precedes a method name, followed by an optional list of ARGUMENT variables in PARENTHESES.
49.

Which characters is used to access property variables on an object-by-object basis?(a) ::(b) =(c) ->(d) .This question was addressed to me by my college director while I was bunking the class.Asked question is from Object Basics-1 topic in portion Objects and Databases in PHP of PHP

Answer»

The CORRECT choice is (c) ->

The EXPLANATION: Example: $PRODUCT1->TITLE=”My Life”;

50.

Code that uses a class, function, or method is often described as the ____________(a) client code(b) user code(c) object code(d) class codeThis question was addressed to me in an interview for internship.The question is from Object Basics-1 in chapter Objects and Databases in PHP of PHP

Answer» RIGHT CHOICE is (a) client code

For explanation: Code that uses a class, function, or method is OFTEN DESCRIBED as the class’s, function, or method client or as client code.