Question-91. How will you parse an XML document using PHP ?

Answer- PHP 5’s new SimpleXML module makes parsing an XML document, well, simple. It turns an XML document into an object that provides structured access to the XML. To create a SimpleXML object from an XML document stored in a string, pass the string to simplexml_load_string( ). It returns a SimpleXML object.

Question-92. Can you create a class in PHP ?

Answer- Yes.

Question-93. How will you add a constructor function to a PHP class ?

Answer- PHP provides a special function called __construct() to define a constructor. You can pass as many as arguments you like into the constructor function.

Question-94. How will you add a destructor function to a PHP class ?

Answer- Like a constructor function you can define a destructor function using function __destruct(). You can release all the resourceses with-in a destructor.

Question-95. How will you access the reference to same object within the object in PHP ?

Answer- The variable $this is a special variable and it refers to the same object i.e. itself.

Question-96. How will you create objects in PHP ?

Answer- Once you defined your class, then you can create as many objects as you like of that class type. Following is an example of how to create object using new operator.

$physics = new Books;
$maths = new Books;
$chemistry = new Books;

 

Question-97. How will you call member functions of a class in PHP ?

Answer- After creating your objects, you will be able to call member functions related to that object. One member function will be able to process member variable of related object only. Following example shows how to set title and prices for the three books by calling member functions.

$physics−>setTitle( "Physics for High School" );
$chemistry−>setTitle( "Advanced Chemistry" );
$maths−>setTitle( "Algebra" );
$physics−>setPrice( 10 );
$chemistry−>setPrice( 15 );
$maths−>setPrice( 7 );

 

Question-98. What is function overriding ?

Answer- Function definitions in child classes override definitions with the same name in parent classes. In a child class, we can modify the definition of a function inherited from parent class.

Question-99. What are interfaces in PHP ?

Answer- Interfaces are defined to provide a common function names to the implementors. Different implementors can implement those interfaces according to their requirements. You can say, interfaces are skeltons which are implemented by developers.

Question-100. What is the use of final keyword ?

Answer- PHP 5 introduces the final keyword, which prevents child classes from overriding a method by prefixing the definition with final. If the class itself is being defined final then it cannot be extended.

[/vc_column_text][/vc_column][/vc_row]