note 33733 added to language.oop

From: Date: Sat, 05 Jul 2003 19:39:58 +0000
Subject: note 33733 added to language.oop
Groups: php.notes 
Request: Send a blank email to php-notes+get-51567@lists.php.net to get a copy of this message
In a recent project of mine I needed a linked list, but as there are no pointer variables in PHP, I came up with the following kludge using array indexes instead of memory adresses: <?php /* the null pointer is represented by the integer value 0, indexes(/memory adresses) are assigned starting at 1 */ class linkable { static $first; var $prev; var $next; var $dust_puppy; function linkable ( $f_prev, $data ) { $this->prev = $f_prev; $this->dust_puppy = $data; $this->next = 0; } } linkable::$first = 1; $linked_list = Array ( ); function new_item ( $data ) { if ( !$linked_list [linkable::$first] )/* we need to capture an empty list */ { $linked_list [linkable::$first] = new linkable; return; } $item = linkable::$first; while ( $linked_list [$item]->next ) $item = $linked_list [$item]->next; $linked_list [$item + 1] = new linkable ( $item, $data ); } ?> ---- Manual Page -- http://www.php.net/manual/en/language.oop.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33733 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33733&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33733&report=yes

« previous php.notes (#51567) next »