note 33733 deleted from language.oop by aidan

From: Date: Sat, 03 Jul 2004 14:51:44 +0000
Subject: note 33733 deleted from language.oop by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72444@lists.php.net to get a copy of this message
Note Submitter: arnsholt@online.no ---- 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 ); } ?>

« previous php.notes (#72444) next »