note 39782 added to language.oop.newref

From: Date: Tue, 10 Feb 2004 14:56:49 +0000
Subject: note 39782 added to language.oop.newref
Groups: php.notes 
Request: Send a blank email to php-notes+get-64958@lists.php.net to get a copy of this message
/*Original 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; 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(); //creating new list a //appending 1 to list //appending 2 to list //creating new list b... using global list //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] => 3 //list[3] => 4 //list[4] => 5 //list[5] => 6 //Contents of a: //list[0] => 1 //list[1] => 2 //list[2] => 3 //list[3] => 4 //list[4] => 5 //list[5] => 6 */ /*Modify /*Modify //http://kr.php.net/manual/kr/language.oop.newref.php class StaticList { var $list = 0; function StaticList($name = '') { global $master; if (!isset($master)) { print "creating new list $name<Br>\n"; $this->list = $master = array(); $master[]=$this;//ObjMaxPoint }else { print "creating new list $name... using global list<br>\n"; } $master[] =& $this;//Use Inventory $this->list = array(); return ($this); } function ocount() {} function asort() {} function bsort() {} 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 max() { global $master; for($i=1;$i<count($master);$i++) { for($j=0;$j<count($master[$i]->list);$j++) $master[0]->append($master[$i]->list[$j]); } return true; } 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); //$b->max(); $c =& new StaticList("c"); $c->append(7); $c->max(); print "Contents of a:<br>\n"; $a->show(); print "Contents of b:<br>\n"; $b->show(); print "Contents of c:<br>\n"; $c->show(); print "Contents of All:<br>\n"; $master[0]->show(); //creating new list a //creating new list b... using global list //creating new list c... using global list //Contents of a: //list[0] => 1 //list[1] => 2 //list[2] => 5 //Contents of b: //list[0] => 3 //list[1] => 4 //list[2] => 6 //Contents of c: //list[0] => 7 //Contents of All: //list[0] => 1 //list[1] => 2 //list[2] => 5 //list[3] => 3 //list[4] => 4 //list[5] => 6 //list[6] => 7 //Array ( [0] => staticlist Object ( [list] => Array ( [0] => 1 [1] => 2 [2] => 5 [3] => 3 [4] => 4 [5] => 6 [6] => 7 ) ) //[1] => staticlist Object ( [list] => Array ( [0] => 1 [1] => 2 [2] => 5 ) ) //[2] => staticlist Object ( [list] => Array ( [0] => 3 [1] => 4 [2] => 6 ) ) //[3] => staticlist Object ( [list] => Array ( [0] => 7 ) ) ) */ ---- Manual Page -- http://www.php.net/manual/en/language.oop.newref.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+39782 Delete -- http://master.php.net/manage/user-notes.php?action=delete+39782&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+39782&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#64958) next »