Q4 0 Notes Adv PHP

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Q4

a) What is Inheritance? Explain with suitable example.


Ans:- What is Inheritance?
• Inheritance is a relationship between two or more classes where derived class inherits
properties of pre- existing (base) classes.
Example:
Base Class: It is the class whose properties are inherited by another class. It is also called Super
Class or Parent Class.
Derived Class: It is the class that inherit properties from base class(es). It is also called Sub Class
or Child Class.
b) How articles are created in Drupal R. Joomala?
Ans:-In Drupal and Joomla, articles are typically created through the administrative
interface of the respective content management systems (CMS). Users with appropriate
permissions can access the backend, navigate to the content creation section, and then
select the option to create a new article. They can then input the title, content,
categorization, tags, and other relevant details before saving the article.
c) Create a XML file which gives details of books availabel in "ABC Bookstore" from following.
Categories i) Technical ii) Cooking iii) YOGA.
Ans:-<bookstore>
<category name="Technical">
<book>
<title>Introduction to Algorithms</title>
<author>Thomas H. Cormen</author>
<price>50.00</price>
</book>
<book>
<title>Clean Code</title>
<author>Robert C. Martin</author>
<price>35.00</price>
</book>
</category>
<category name="Cooking">
<book>
<title>The Joy of Cooking</title>
<author>Irma S. Rombauer</author>
<price>20.00</price>
</book>
<book>
<title>Mastering the Art of French Cooking</title>
<author>Julia Child</author>
<price>30.00</price>
</book>
</category>
<category name="YOGA">
<book>
<title>The Heart of Yoga</title>
<author>T.K.V. Desikachar</author>
<price>25.00</price>
</book>
<book>
<title>Light on Yoga</title>
<author>B.K.S. Iyengar</author>
<price>18.00</price>
</book>
</category>
</bookstore>
d) Define class Employee having private members id, name department, Salary. Define
parameterized constructor. Create a Subclass called "Manager" with private member bonus.
Create 6 objects of the Manager class and display the details of the Manager having the
maximum total salary. (Salary + bonus).
Ans:- <?php
class Employee {
private $id;
private $name;
private $department;
private $salary;
public function __construct($id, $name, $department, $salary) {
$this->id = $id;
$this->name = $name;
$this->department = $department;
$this->salary = $salary;
}
public function getSalary() {
return $this->salary;
}
public function getName() {
return $this->name;
}
}
class Manager extends Employee {
private $bonus;
public function __construct($id, $name, $department, $salary, $bonus) { parent::__construct($id,
$name, $department,
e) Explain setting Response Headers.
Ans:- Response headers are part of HTTP responses sent from a web server to a client
(e.g., a browser) containing additional information about the server's response. Setting
response headers involves specifying these additional details before sending the actual
content of the response. Examples of response headers include Content-Type, Content-
Length, and Cache-Control. They can be set in various programming languages like PHP,
Python, or JavaScript to control aspects of the response such as content type, caching
behavior, and security settings.

a) Explain the structure of WSDL.


Ans:- WSDL (Web Services Description Language) structure typically comprises
definitions of the service, its port types, bindings, and operations. It defines the
methods available, their parameters, and the data types they use.

b) Explain XML Parser.


Ans:- An XML parser is a software module or program that reads XML documents
and interprets its contents for various purposes, such as data extraction, validation,
or transformation. It parses the XML document according to the rules of the XML
specification.

c) Write a PHP script to display server information in table format (Use $_SERVER).
Ans:- <table>
<tr>
<th>Variable</th>
<th>Value</th>
</tr>
<?php
foreach ($_SERVER as $key => $value) {
echo "<tr><td>$key</td><td>$value</td></tr>";
}
?>
</table>
d) What are the advantages of AJAX?

Ans:- Advantages of AJAX (Asynchronous JavaScript and XML) include:


 Improved user experience with asynchronous updates, reducing page reloads.
 Enhanced interactivity by fetching data without interrupting the user's interaction.
 Bandwidth efficiency as only necessary data is fetched, reducing server load.
 Compatibility across different platforms and browsers, enhancing cross-browser
support.
e) Write a PHP Script to read book. XML and print book details in tabular format using simple
XML. (Content of book. XML are (bookcode, bookname, author, year, price).
Ans:- <?php
$books = simplexml_load_file('books.xml');
echo "<table border='1'>";
echo "<tr><th>Book Code</th><th>Book
Name</th><th>Author</th><th>Year</th><th>Price</th></tr>";
foreach ($books as $book) {
echo "<tr>";
echo "<td>" . $book->bookcode . "</td>";
echo "<td>" . $book->bookname . "</td>";
echo "<td>" . $book->author . "</td>";
echo "<td>" . $book->year . "</td>";
echo "<td>" . $book->price . "</td>";
echo "</tr>";
}
echo "</table>";
?>
a) What is introspection? Explain get_class_methods( ) and get_ class _vars( ) with suitble
example?

Ans:- Introspection: Introspection is the ability of a program to examine its own


structure and state. In PHP, ‘get_class_methods()’ and ‘get_class_vars()’ are functions that
allow you to introspect classes. ‘get_class_methods()’ returns an array of method names for
a given class, and ‘get_class_vars()’ returns an associative array of class properties and
their values.
Example:

class MyClass {
public $prop1;
public function method1() {
// method code
}
}
$methods = get_class_methods('MyClass');
$vars = get_class_vars('MyClass');
print_r($methods); // Output: Array ( [0] => method1 )
print_r($vars); // Output: Array ( [prop1] => )
b) What is Inheritance? Explain with suitable example.

Ans:- Inheritance: Inheritance is a mechanism in object-oriented programming where


a class (subclass) can inherit properties and methods from another class (superclass).
The subclass can then extend or override these inherited properties and methods.

Example:

class Animal {
public function sound() {
echo "Animal makes a sound";
}
}
class Dog extends Animal {
public function sound() {
echo "Dog barks";
}
}
$dog = new Dog();
$dog->sound(); // Output: Dog barks
c) Explain with example how to connect database using PHP and Ajax.
Ans:- Connecting to a database using PHP and Ajax involves sending requests
from the client-side (browser) to the server-side (PHP script), which interacts with
the database and returns data asynchronously.
Example:
// PHP script (connect_db.php)
$conn = new mysqli("localhost", "username", "password", "database");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Ajax request (script.js)
$.ajax({
url: 'connect_db.php',
type: 'POST',
data: { key: 'value' },
success: function(response) {
console.log(response);
}
});
d) Explain mouse & keyboards event in JavaScript.
Ans:- Mouse & Keyboard Events in JavaScript: Mouse and keyboard
events in JavaScript allow you to respond to user interactions such as clicks, key
presses, mouse movements, etc.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Mouse & Keyboard Events</title>
</head>
<body>
<button id="myButton">Click Me</button>
<input type="text" id="myInput">
<script> document.getElementById('myButton').addEventListener('click', function() {
alert('Button clicked!');
}); document.getElementById('myInput').addEventListener('keypress',
function(event) {
console.log('Key pressed:', event.key);
});
</script>
</body>
</html>
e) Create a XML file which gives details of books available in “Bookstore” From following
categories
i) Computer
ii) Cooking
iii) YOGA
Ans:-
<Bookstore>
<Category name="Computer">
<Book>
<Title>Introduction to Algorithms</Title>
<Author>Thomas H. Cormen</Author>
<ISBN>978-0262533058</ISBN>
</Book>
<Book>
<Title>Clean Code: A Handbook of Agile Software Craftsmanship</Title>
<Author>Robert C. Martin</Author>
<ISBN>978-0132350884</ISBN>
</Book>
</Category>
<Category name="Cooking">
<Book>
<Title>The Joy of Cooking</Title>
<Author>Irma S. Rombauer</Author>
<ISBN>978-1501174076</ISBN>
</Book>
<Book>
<Title>Mastering the Art of French Cooking</Title>
<Author>Julia Child</Author>
<ISBN>978-0241956465</ISBN>
</Book>
</Category>
<Category name="Yoga">
<Book>
<Title>The Heart of Yoga: Developing a Personal Practice</Title>
<Author>T.K.V. Desikachar</Author>
<ISBN>978-0892817641</ISBN>
</Book>
<Book>
<Title>Light on Yoga</Title>
<Author>B.K.S. Iyengar</Author>
<ISBN>978-0805210316</ISBN>
</Book>
</Category>
</Bookstore>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy