note 39764 added to language.oop.newref
| From: | blueshadow822 at hotmail dot com | Date: | Tue, 10 Feb 2004 08:20:47 +0000 |
| Subject: | note 39764 added to language.oop.newref | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64923@lists.php.net to get a copy of this message | ||
Original : rick_php_net at roundeye dot net
Date : 01-Oct-2002 05:37
Modify : bitmore.co.kr
class StaticList {
var $list = 0;
function StaticList($name = '') {
global $master;
if (!isset($master)) {
print "creating new list $name<Br>\n";
//$master = $this;
$master =& $this;
$master->list = array();
}else {
print "creating new list $name... using global list<br>\n";
}
//$this->list =& $master->list;
//$this->list = $master->list;
return ($this);
}
function show() {
if (is_array($this->list)) {
if (count($this->list)) {
reset($this->list);
while (list($key, $value) = each($this->list)) {
print "list[$key] => $value<br>\n";
}
}else {
print "list empty.<br>\n";
}
}else {
print "list is not a list.<br>\n";
}
}
function append($val) {
if (!is_array($this->list)) {
print "forced to create list...<br>\n";
$this->list = array();
}else {
print "appending $val to list<br>\n";
$this->list[] = $val;
}
}
}
$a = new StaticList("a");
$a->append(1);
$a->append(2);
$b = new StaticList("b");
$b->append(3);
$b->append(4);
$a->append(5);
$b->append(6);
print "Contents of a:<br>\n";
$a->show();
print "Contents of a:<br>\n";
$b->show();
this Show Printing
creating new list a
appending 1 to list
appending 2 to list
creating new list b
appending 3 to list
appending 4 to list
appending 5 to list
appending 6 to list
Contents of a:
list[0] => 1
list[1] => 2
list[2] => 5
Contents of a:
list[0] => 3
list[1] => 4
list[2] => 6
----
Manual Page -- http://www.php.net/manual/en/language.oop.newref.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39764
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39764&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39764&report=yes
Search -- http://master.php.net/manage/user-notes.php