|
Posted by carlton on 10/31/05 23:31
This section of code has been driving me mad for hours.
I don't understand why it generates the following output.
PRIOR TO call to setName(some text) item->name=an item.= ((OK))
AFTER TO call to setName(widget + number) item->name=widget 5442 ()OK))
class item operates correctly. ((OK))
ORIGINAL LIST NAME ( direct ) IS =><= ((??)) should be EMPTY
Fatal error: Call to undefined function: getname() in
/var/www/html/test_cpicturelist.php on line 102 ((??)) why does this not
work when item->getName() works??
<?php
print"<TITLE> T E S T C_PictureLIst{} </TITLE>";
/*
This is a .php script to test the operation of the C_PictureList class
The aim is to create a class, add data to it, then extract it to the screen.
*/
$sourcefile;
$sourcefile = '/var/www/html/class.php';
print "<H2>file <FONT COLOR='RED'>test_cpicturelist.php</FONT> in
/var/www/html</H2>";
print "End of parsing test_cpicturelist.php<BR>";
if ( !class_exists( "C_PictureList" ) )
{
class C_PictureList{
//
// The class C_PictureList contains information about a set of pictures,
namely the picture name, file size
// and the number of pictures in the group.
// The main purpose of the class is to be part of the catagory class.
// All pictures assumed to be in a common directory.
//
var $listname; // name of the list
var $numpics; // number of pictures in the catagory.
function C_PictureList($listname='NOT SET',$numpics=0){ // use the
constructor function to initialise any $this variables.
$this->listname="EMPTY"; // name of the list
$this->numpics=-1; // use -ve number to indicate an uninitialised list.
}
function setName($name){ // set the name of the list
$this->listname=$name;
}
function getName(){ // retrieve the name of the list
return $this->listname;
}
var $filename = array(); // array of file names for this list
var $filesize = array(); // corresponding array of file sizes
function ListPictures() //// adjust this to generate a table at a
later date.
{
print "<BR>";
print "There are $numpics Pictures in list name $listname<BR>";
foreach ($this->filename as $filename)
{
print"filename = $filename<BR>";
}
}
function AddPicture($picture) //// Use this function to add new
pictures to the structure.
{
array_push($this->filename, $picture); // add file name
array_push($this->filesize, filesize($picture)); // add file size
$this->$numpics = $this->$numpics+1; // increment picture counter
}
}// end of class C_PictureList
}// end of class_exists wrapper
//
// The catagory class is a set of pictures witha commin theme -
geerally,pictures within a given directory.
// The class consists of a class name and a picture list.
// All pictures assumed to be in a common directory.
//
if ( !class_exists( "C_Catagory" ) )
{
class C_Catagory{
// var $name = array(); changed to var $catname="";
var $catname; // name of the catagory (= directory name, set
using the LocateCatagories function)
var $PictureList = array();// define the variable here, then use
the constructor to initialise it.
function C_Category() {
$this->PictureList[] = new C_PictureList();
$this->catname="UNKNOWN";
}
// var $PictureList = new C_PictureList(); // array containing picture
details.
}// end of class C_Category
}// end of class_exists wrapper
//>Set Catagory Directory
// The AllCatagories valiable contains
//================= S I M P L E C L A S S T E S T.
=============================//
class item{
var $name="";
function item(){// use the constructor function to initialise any $this
variables.
$this->name="an item.";
}
function setName($n){
$this->name=$n;
}
function getName(){
return $this->name;
}
}
91: $testitem=new item();
92: print"PRIOR TO call to setName(some text) item->name=". 93:
$testitem->getName()."=<BR>";
93: $testitem->setName("widget 5442<BR> class item operates correctly.
<BR><BR>");
95: print "AFTER TO call to setName(widget + number) item->name="
..$testitem->getName();
96: //================= S I M P L E C L A S S T T E S T.
===========================//
97: $AllCatagories=new C_Catagory();
98: print"ORIGINAL LIST NAME ( direct ) IS <FONT
COLOR='BLUE'>=>".$AllCatagories->listname."<=</FONT><BR>";
99: print $AllCatagories->getName();
100: print"ORIGINAL LIST NAME ( getName ) IS <FONT
COLOR='BLUE'>".$AllCatagories->getName(). "</FONT><BR>";
101: $AllCatagories->setName("test list");
102: print"TEST LIST NAME ( direct ) IS <FONT
COLOR='BLUE'>".$AllCatagories->listname."</FONT><BR>";
103: print"TEST LIST NAME ( getName ) IS <FONT
COLOR='BLUE'>".$AllCatagories->getName()."</FONT><BR>";
104: // end of the php script
?>
Navigation:
[Reply to this message]
|