Write PHP script to
demonstrate the concept of introspection for examining object.
<?php
class Myclass
{
public $a;
public $b=1;
public $c='Archana';
function Myclass()
{
//Myclass function
}
function myfun1()
{
//functin
}
function myfun2()
{
//functin
}
}
$class=get_declared_classes();
foreach($class as $cname)
{
echo"$cname<br>";
}
echo"<br>Class Methods
are : <br>";
$m=get_class_methods('Myclass');
foreach($m as $mname)
{
echo"$mname<br>";
}
$cp=get_class_vars('Myclass');
echo"class variables are
:<br>";
foreach($cp as $cpname => $v)
{
echo"$cpname : $v
<br>";
}
?>
2)Create a XML file
which gives details of books available in “ABC Bookstore” from following
categories.
1) Technical
2) Cooking
3) Yoga
and elements in each
category are in the following format
<Book>
<Book_PubYear> --------------</Book_PubYear>
<Book_Title> --------------</Book_Title>
<Book_Author> ---------------</Book_Author>
</Book>
Save the file as
“Book.xml”
Create an application
that reads “Book.xml” file into simple XML object. Display attributes and
elements.
(Hint: Use
simple_xml_load_file() function)
abcbook.xml
<?xml
version="1.0"?>
<ABCBOOK>
<Technical>
<BOOK>
<Book_PubYear>ABC</Book_PubYear>
<Book_Title>pqr</Book_Title>
<Book_Author>400</Book_Author>
</BOOK>
</Technical>
<Cooking>
<BOOK>
<Book_PubYear>BBC</Book_PubYear>
<Book_Title>pPr</Book_Title>
<Book_Author>500</Book_Author>
</BOOK>
</Cooking>
<Yoga>
<BOOK>
<Book_PubYear>CBC</Book_PubYear>
<Book_Title>pRr</Book_Title>
<Book_Author>600</Book_Author>
</BOOK>
</Yoga>
</ABCBOOK>
abcbook.php
<?php
$xml=simplexml_load_file("abcbook.xml") or die("cannnot
load");
$xmlstring=$xml->asXML();
echo $xmlstring;
?>
Another solution
Abcbook.xml
<?xml version='1.0'
encoding ='UTF-8' ?>
<bookstore>
<books
category="technical">
<book_no>1</book_no>
<book_name>def</book_name>
<author_name>xxx</author_name>
<price>100</price>
<year>1990</year>
</books>
<books
category="Cooking">
<book_no>2</book_no>
<book_name>ccc</book_name>
<author_name>aaa</author_name>
<price>200</price>
<year>1950</year>
</books>
<books
category="YOGA">
<book_no>3</book_no>
<book_name>ddd</book_name>
<author_name>zzz</author_name>
<price>150</price>
<year>2016</year>
</books>
</bookstore>
Abcbook.php
<?php
$xml=simplexml_load_file("Abcbook.xml") or die("cannnot load");
var_dump($xml);
?>