Пример #1
1
 public function addText(SimpleToken $text, $parent = null)
 {
     if ($parent) {
         $parent->addChild($text->getValue());
     } else {
         parent::push($text->getValue());
     }
 }
Пример #2
0
function get_result($t, $ladders, $snakes)
{
    fill_graph($t, $ladders);
    fill_graph($t, $snakes);
    $len = count($t);
    $vertices = array();
    for ($k = 0; $k < $len; $k++) {
        $vertices[$k] = new vertex($k);
    }
    $adjacencyList = array();
    for ($u = 0; $u < $len; $u++) {
        $list = new SplDoublyLinkedList();
        for ($v = 0; $v < $len; $v++) {
            if ($t[$u][$v] != 0) {
                $list->push(array('vertex' => $vertices[$v], 'distance' => $t[$u][$v]));
            }
        }
        $list->rewind();
        $adjacencyList[] = $list;
    }
    calcShortestPaths($vertices[0], $adjacencyList);
    $path = end($vertices)->path;
    $result = $p = 0;
    for ($n = 0; $n < count($path); $n++) {
        $p++;
        if (@$path[$n + 1] - $path[$n] != 1) {
            $result = $result + ceil(($p - 1) / 6);
            $p = 0;
        }
    }
    //echo "[" . implode(', ', $path) . "]\n\n";
    return $result;
}
Пример #3
0
function resetCreateGlobalVars()
{
    global $v0, $v1, $v2, $v3, $v4, $v5, $list0, $list1, $list2, $list3, $list4, $list5, $adjacencyList;
    $v0 = new vertex(0);
    $v1 = new vertex(1);
    $v2 = new vertex(2);
    $v3 = new vertex(3);
    $v4 = new vertex(4);
    $v5 = new vertex(5);
    $list0 = new SplDoublyLinkedList();
    $list0->push(array('vertex' => $v1, 'distance' => 3));
    $list0->push(array('vertex' => $v3, 'distance' => 1));
    $list0->rewind();
    $list1 = new SplDoublyLinkedList();
    $list1->push(array('vertex' => $v0, 'distance' => 3));
    $list1->push(array('vertex' => $v2, 'distance' => 7));
    $list1->rewind();
    $list2 = new SplDoublyLinkedList();
    $list2->push(array('vertex' => $v1, 'distance' => 7));
    $list2->push(array('vertex' => $v3, 'distance' => 8));
    $list2->push(array('vertex' => $v4, 'distance' => 12));
    $list2->rewind();
    $list3 = new SplDoublyLinkedList();
    $list3->push(array('vertex' => $v0, 'distance' => 1));
    $list3->push(array('vertex' => $v2, 'distance' => 8));
    $list3->rewind();
    $list4 = new SplDoublyLinkedList();
    $list4->push(array('vertex' => $v2, 'distance' => 12));
    $list4->push(array('vertex' => $v5, 'distance' => 3));
    $list4->rewind();
    $list5 = new SplDoublyLinkedList();
    $list5->push(array('vertex' => $v4, 'distance' => 3));
    $list5->rewind();
    $adjacencyList = array($list0, $list1, $list2, $list3, $list4, $list5);
}
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function getOpcode()
 {
     if (count($this->_frames) == 0) {
         throw new \UnderflowException('No frames have been added to this message');
     }
     return $this->_frames->bottom()->getOpcode();
 }
Пример #5
0
 function __construct()
 {
     $this->listClients = new SplDoublyLinkedList();
     //=========================load file===============================//
     $read = new ReadCsv();
     $lisClient = $read->get2DArrayFromCsv('files/clientes.csv', ',');
     foreach ($lisClient as $row => $data) {
         $listProductByClient = new SplDoublyLinkedList();
         $contLines = 0;
         $codeProduct = 0;
         foreach ($data as $rowL => $dataL) {
             if ($rowL > 1 && $dataL != "") {
                 if ($contLines == 0) {
                     $codeProduct = $dataL;
                     $contLines++;
                 } else {
                     $listProdCliente = new ListaProductosPorCliente();
                     $listProdCliente->setIdProducto($codeProduct);
                     $listProdCliente->setProducto($dataL);
                     $listProductByClient->push($listProdCliente);
                     $contLines--;
                 }
             }
         }
         $client1 = new Clientes();
         $client1->setName($data[0]);
         $client1->setId($data[1]);
         $client1->setListPruductByClient($listProductByClient);
         $this->listClients->push($client1);
     }
     //=========================//load file=============================//
     $this->listClients->serialize();
     //$this->loadFile();
 }
 /**
  * @param $vertex
  * @return \SplDoublyLinkedList
  */
 public function createTransitionsList($vertex)
 {
     $list = new \SplDoublyLinkedList();
     $list->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO | \SplDoublyLinkedList::IT_MODE_KEEP);
     $list->push($vertex);
     return $list;
 }
Пример #7
0
 /**
  * @todo make recursive
  * 
  * Reads a stream character for character until the suffix ('e') is found
  * and returns the remainder of the string.
  *
  * @param string $stream Reads the stream into the buffer.
  *
  * @throws Bencode\Exceptions\IntegerException
  */
 public function decode($stream)
 {
     $flag = false;
     $stream = str_split($stream);
     $buffer = '';
     $size = count($stream);
     $stack = new \SplDoublyLinkedList();
     for ($i = 0; $i < $size - 1; $i++) {
         if ($flag) {
             if (is_numeric($stream[$i]) || $stream[$i] === '-') {
                 $stack->push($stream[$i]);
             }
         }
         if ($stream[$i] === 'i') {
             $flag = true;
         }
         if ($stream[$i] === 'e') {
             $flag = false;
             unset($stream[$i]);
             break;
         }
         unset($stream[$i]);
     }
     foreach ($stack as $s) {
         $buffer .= $s;
     }
     $this->_buffer = $buffer;
     return implode('', array_values($stream));
 }
Пример #8
0
 /**
  * Reads a stream and decodes the byte character by character. This method
  * will return the remainder of the stream.
  *
  * @param  string $stream The stream to be decoded.
  * @return string         The remainder of the stream, if any.
  */
 public function decode($stream)
 {
     $stream = str_split($stream);
     $buffer = '';
     $size = count($stream);
     $sizeList = new \SplDoublyLinkedList();
     $bufList = new \SplDoublyLinkedList();
     // read the size of the byte from the stream
     for ($i = 0; $i < count($stream); $i++) {
         $temp = $stream[$i];
         unset($stream[$i]);
         if ($temp === ':') {
             break;
         }
         $sizeList->push($temp);
     }
     $stream = array_values($stream);
     $size = 0;
     foreach ($sizeList as $sl) {
         $size .= $sl;
     }
     // read the length of the byte from the stream
     for ($i = 0; $i < $size; $i++) {
         $bufList->push($stream[$i]);
         unset($stream[$i]);
     }
     // read the byte into the buffer
     foreach ($bufList as $bl) {
         $buffer .= $bl;
     }
     $this->_buffer = $buffer;
     return implode('', array_values($stream));
 }
Пример #9
0
 public function resolve($obj)
 {
     $result = new \SplDoublyLinkedList();
     foreach ($obj as $value) {
         $result->push($value);
     }
     return $result;
 }
Пример #10
0
 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested)
 {
     $mode = $c->getIteratorMode();
     $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
     $a += array("~mode" => new ConstStub(($mode & \SplDoublyLinkedList::IT_MODE_LIFO ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO') . ' | ' . ($mode & \SplDoublyLinkedList::IT_MODE_KEEP ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode), "~dllist" => iterator_to_array($c));
     $c->setIteratorMode($mode);
     return $a;
 }
Пример #11
0
 public static function castDoublyLinkedList(\SplDoublyLinkedList $c, array $a, Stub $stub, $isNested)
 {
     $prefix = Caster::PREFIX_VIRTUAL;
     $mode = $c->getIteratorMode();
     $c->setIteratorMode(\SplDoublyLinkedList::IT_MODE_KEEP | $mode & ~\SplDoublyLinkedList::IT_MODE_DELETE);
     $a += array($prefix . 'mode' => new ConstStub(($mode & \SplDoublyLinkedList::IT_MODE_LIFO ? 'IT_MODE_LIFO' : 'IT_MODE_FIFO') . ' | ' . ($mode & \SplDoublyLinkedList::IT_MODE_KEEP ? 'IT_MODE_KEEP' : 'IT_MODE_DELETE'), $mode), $prefix . 'dllist' => iterator_to_array($c));
     $c->setIteratorMode($mode);
     return $a;
 }
Пример #12
0
 public function process($index, \SplDoublyLinkedList $list)
 {
     $first = $list->offsetGet($index - 1);
     $second = $list->offsetGet($index + 1);
     $result = $first * $second;
     $list->offsetSet($index - 1, $result);
     unset($list[$index]);
     unset($list[$index]);
 }
Пример #13
0
function test(SplDoublyLinkedList $l)
{
    $l->push("a");
    $l->push("b");
    $l->push("c");
    echo "ArrayAccess Unset:", PHP_EOL;
    unset($l[0]);
    var_dump($l[0]);
    echo PHP_EOL;
}
 /**
  * {@inheritdoc}
  */
 public function tokenize($userAgent)
 {
     $iterator = new \SplDoublyLinkedList();
     $iterator->setIteratorMode(\SplDoublyLinkedList::IT_MODE_FIFO);
     foreach ($this->getTokens($userAgent) as $position => $token) {
         $token = trim($token);
         $iterator->push(new Node($token, $position, $this->resolveType($token)));
     }
     return $iterator;
 }
Пример #15
0
 public function process($index, \SplDoublyLinkedList $list)
 {
     $first = $list->offsetGet($index - 1);
     $second = $list->offsetGet($index + 1);
     if ($second == 0) {
         throw new \Exception('zero division error');
     }
     $result = $first / $second;
     $list->offsetSet($index - 1, $result);
     unset($list[$index]);
     unset($list[$index]);
 }
Пример #16
0
 public function testPHPUnitCommand()
 {
     // need an explicit Traversable
     $skippedPaths = new \SplDoublyLinkedList();
     $skippedPaths->push('a');
     $skippedPaths->push('b');
     // going for 'bang for the buck' here re: test converage
     $task = (new \Robo\Task\ApiGen\ApiGen('apigen'))->config('./apigen.neon')->source('src')->extensions('php')->exclude(array('test', 'tmp'))->skipDocPath($skippedPaths)->charset(array('utf8', 'iso88591'))->internal('no')->php(true)->tree('Y')->debug('n');
     $cmd = 'apigen --config ./apigen.neon --source src --extensions php --exclude test --exclude tmp --skip-doc-path a --skip-doc-path b --charset \'utf8,iso88591\' --internal no --php yes --tree yes --debug no';
     verify($task->getCommand())->equals($cmd);
     $task->run();
     $this->apigen->verifyInvoked('executeCommand', [$cmd]);
 }
Пример #17
0
 /**
  * Gets an iterator that iterates over each article.
  *
  * This list is never cached.
  *
  * @param bool $unpublished Whether articles not yet published should be fetched.
  */
 public function getIterator($unpublished = false) : \Iterator
 {
     $articles = new \SplDoublyLinkedList();
     foreach (new \GlobIterator($this->path . '/*.md') as $file) {
         if ($file->isFile()) {
             $article = $this->getArticleFromFile($file->getFilename());
             if ($unpublished || !$article->date()->isFuture()) {
                 $articles->unshift($article);
             }
         }
     }
     return new \IteratorIterator($articles);
 }
Пример #18
0
 /**
  * Returns true, if the item has any listeners.
  *
  * @return Boolean
  */
 public function hasListeners()
 {
     if ($this->_listeners === null) {
         return false;
     }
     return $this->_listeners->count() > 0;
 }
 /**
  * Retrieve the maintenance task entry, from unique identfier
  * @param $maintenanceTaskEntryIdentifier   Identifier to locate entry
  * @return mixed|null                       Returns the maintenance task entry or null on error
  * @throws InvalidArgumentException         if the provided argument is not set or of correct type
  */
 public function retrieveMaintenanceTaskEntry($maintenanceTaskEntryIdentifier)
 {
     if (!isset($maintenanceTaskEntryIdentifier)) {
         //argument check
         throw new InvalidArgumentException("Missing Argument");
     } else {
         if (!is_numeric($maintenanceTaskEntryIdentifier)) {
             //argument check
             throw new InvalidArgumentException("maintenanceTaskEntryIdentifier is not a number");
         }
     }
     if ($this->maintenanceTaskList->isEmpty()) {
         //if list is empty, unable to return entry
         return null;
     } else {
         $this->maintenanceTaskList->setIteratorMode(SplDoublyLinkedList::IT_MODE_FIFO);
         //set iteration FIFO
         for ($this->maintenanceTaskList->rewind(); $this->maintenanceTaskList->valid(); $this->maintenanceTaskList->next()) {
             if ($this->maintenanceTaskList->current()->getTaskEntryIdentifier() == $maintenanceTaskEntryIdentifier) {
                 //if entry identifier matches supplied identifier
                 return $this->maintenanceTaskList->current();
             }
             //return the matching entry
         }
     }
     return null;
     //entry with given identifier not found
 }
Пример #20
0
 /**
  * Dispatch
  * @return mixed
  */
 private function dispatch()
 {
     // for each route
     for (; $this->routes->valid(); $this->routes->next()) {
         $route = $this->routes->current();
         // if method is OK
         if (strtoupper($route['method']) === $this->method || $route['method'] === '*') {
             $regex = $this->normalizeRegex($route['path']);
             // if path is OK
             if (preg_match("@^{$regex}@", $this->uri, $matches)) {
                 $callback = $route['callback'];
                 $req = new \ArrayObject();
                 $req->params = (object) $matches;
                 $req->uri = $this->uri;
                 $req->path = $this->path;
                 $req->query = $this->query;
                 if ($this->method !== 'GET') {
                     if (!isset($data)) {
                         parse_str(file_get_contents("php://input"), $data);
                     }
                     $req->body = $data;
                 }
                 $that = $this;
                 $next = function () use($that) {
                     $that->routes->next();
                     $that->dispatch();
                 };
                 return $callback($req, $next);
             }
         }
     }
 }
Пример #21
0
 /**
  * (excerpt from http://docs.hhvm.com/manual/en/splstack.setiteratormode.php)
  *
  *
  * @mode       mixed   There is only one iteration parameter you can
  *                     modify. The behavior of the iterator (either one or
  *                     the other): SplDoublyLinkedList::IT_MODE_DELETE
  *                     (Elements are deleted by the iterator)
  *                     SplDoublyLinkedList::IT_MODE_KEEP (Elements are
  *                     traversed by the iterator)
  *
  *                     The default mode is 0x2 :
  *                     SplDoublyLinkedList::IT_MODE_LIFO |
  *                     SplDoublyLinkedList::IT_MODE_KEEP Warning
  *
  *                     The direction of iteration can no longer be changed
  *                     for SplStacks. Trying to do so will result in a
  *                     RuntimeException being thrown.
  *
  * @return     mixed   No value is returned.
  */
 public function setIteratorMode($mode)
 {
     if (($mode & self::IT_MODE_LIFO) == 0) {
         throw new RuntimeException('Iterators\' LIFO/FIFO modes for SplStack/SplQueue objects are frozen');
     }
     parent::setIteratorMode($mode);
 }
Пример #22
0
 /**
  * {@inheritdoc}
  */
 public function handle(Exception $exception)
 {
     if ($this->rethrow) {
         throw $exception;
     }
     foreach ($this->handlers as $index => $handler) {
         try {
             if (is_string($handler)) {
                 $handler = $this->resolver->resolve($handler);
                 $this->handlers->offsetSet($index, $handler);
             } else {
                 if (is_array($handler) && is_string($handler[0])) {
                     $handler[0] = $this->resolver->resolve($handler[0]);
                     $this->handlers->offsetSet($index, $handler);
                 }
             }
             if (!$this->matchesTypehint($handler, $exception)) {
                 continue;
             }
             $result = $this->callHandler($handler, $exception);
             if ($result !== null) {
                 return $this->makeResponse($result, $exception);
             }
         } catch (Exception $newException) {
             return $this->handle($newException);
         }
     }
     return $this->makeResponse($this->defaultHandler->handle($exception), $exception);
 }
Пример #23
0
 /**
  * @return boolean
  */
 public function isBinary()
 {
     if ($this->_frames->isEmpty()) {
         throw new \UnderflowException('Not enough data has been received to determine if message is binary');
     }
     return Frame::OP_BINARY === $this->_frames->bottom()->getOpcode();
 }
 /**
  * @param VisitAction $futureVisitAction
  * @param Expression $lastVisitedExpression
  * @return \SplDoublyLinkedList
  */
 protected function prepareQueueForFutureVisits(VisitAction $futureVisitAction = null, Expression $lastVisitedExpression)
 {
     $stackForExpressions = new \SplDoublyLinkedList();
     if ($lastVisitedExpression instanceof ExpressionIterable) {
         foreach ($lastVisitedExpression as $futureVisit) {
             $stackForExpressions->push($futureVisit);
         }
     } else {
         if ($lastVisitedExpression instanceof ExpressionAggregate) {
             $futureVisit = $lastVisitedExpression->getExpression();
             $stackForExpressions->push($futureVisit);
         }
     }
     if ($futureVisitAction instanceof VisitAction) {
         $stackForExpressions->push($futureVisitAction);
     }
     return $stackForExpressions;
 }
Пример #25
0
 /**
  * Perform a depth-first traversal on the provided graph.
  *
  * @param Digraph $graph
  *   The graph on which to perform the depth-first search.
  * @param DepthFirstVisitorInterface $visitor
  *   The visitor object to use during the traversal.
  * @param object|\SplDoublyLinkedList $start
  *   A vertex, or vertices, to use as start points for the traversal. There
  *   are a few sub-behaviors here:
  *     - If an SplDoublyLinkedList, SplQueue, or SplStack is provided, the
  *       traversal will deque and visit vertices contained therein.
  *     - If a single vertex object is provided, it will be the sole
  *       originating point for the traversal.
  *     - If no value is provided, DepthFirst::find_sources() is called to
  *       search the graph for source vertices. These are place into an
  *       SplQueue in the order in which they are discovered, and traversal
  *       is then run over that queue in the same manner as if calling code
  *       had provided a queue directly. This method *guarantees* that all
  *       vertices in the graph will be visited.
  *
  * @throws RuntimeException
  *   Thrown if an invalid $start parameter is provided.
  */
 public static function traverse(Digraph $graph, DepthFirstVisitorInterface $visitor, $start = NULL)
 {
     if ($start === NULL) {
         $queue = self::find_sources($graph, $visitor);
     } else {
         if ($start instanceof \SplDoublyLinkedList) {
             $queue = $start;
         } else {
             if (is_object($start)) {
                 $queue = new \SplDoublyLinkedList();
                 $queue->push($start);
             }
         }
     }
     if ($queue->isEmpty()) {
         throw new RuntimeException('No start vertex or vertices were provided, and no source vertices could be found in the provided graph.', E_WARNING);
     }
     $visiting = new \SplObjectStorage();
     $visited = new \SplObjectStorage();
     $visitor->beginTraversal();
     $visit = function ($vertex) use($graph, $visitor, &$visit, $visiting, $visited) {
         if ($visiting->contains($vertex)) {
             $visitor->onBackEdge($vertex, $visit);
         } else {
             if (!$visited->contains($vertex)) {
                 $visiting->attach($vertex);
                 $visitor->onStartVertex($vertex, $visit);
                 foreach ($graph->successorsOf($vertex) as $head) {
                     $visitor->onExamineEdge($vertex, $head, $visit);
                     $visit($head);
                 }
                 $visitor->onFinishVertex($vertex, $visit);
                 $visiting->detach($vertex);
                 $visited->attach($vertex);
             }
         }
     };
     // TODO experiment with adding a generator-producing visitor method that yields the queue here
     while (!$queue->isEmpty()) {
         $vertex = $queue->shift();
         $visit($vertex);
     }
     $visitor->endTraversal();
 }
Пример #26
0
 /**
  * Perform a depth-first traversal on the provided graph.
  *
  * @param DirectedGraph $graph
  *   The graph on which to perform the depth-first search.
  * @param DepthFirstVisitorInterface $visitor
  *   The visitor object to use during the traversal.
  * @param object|\SplDoublyLinkedList $start
  *   A vertex, or vertices, to use as start points for the traversal. There
  *   are a few sub-behaviors here:
  *     - If an SplDoublyLinkedList, SplQueue, or SplStack is provided, the
  *       traversal will deque and visit vertices contained therein.
  *     - If a single vertex object is provided, it will be the sole
  *       originating point for the traversal.
  *     - If no value is provided, DepthFirst::find_sources() is called to
  *       search the graph for source vertices. These are place into an
  *       SplQueue in the order in which they are discovered, and traversal
  *       is then run over that queue in the same manner as if calling code
  *       had provided a queue directly. This method *guarantees* that all
  *       vertices in the graph will be visited.
  *
  * @throws RuntimeException
  *   Thrown if an invalid $start parameter is provided.
  */
 public static function traverse(DirectedGraph $graph, DepthFirstVisitorInterface $visitor, $start = NULL)
 {
     if ($start === NULL) {
         $queue = self::find_sources($graph, $visitor);
     } else {
         if ($start instanceof \SplDoublyLinkedList) {
             $queue = $start;
         } else {
             if (is_object($start)) {
                 $queue = new \SplDoublyLinkedList();
                 $queue->push($start);
             }
         }
     }
     if ($queue->isEmpty()) {
         throw new RuntimeException('No start vertex or vertices were provided, and no source vertices could be found in the provided graph.', E_WARNING);
     }
     $visiting = new \SplObjectStorage();
     $visited = new \SplObjectStorage();
     $visitor->beginTraversal();
     $visit = function ($vertex) use($graph, $visitor, &$visit, $visiting, $visited) {
         if ($visiting->contains($vertex)) {
             $visitor->onBackEdge($vertex, $visit);
         } else {
             if (!$visited->contains($vertex)) {
                 $visiting->attach($vertex);
                 $visitor->onStartVertex($vertex, $visit);
                 $graph->eachAdjacent($vertex, function ($to) use($vertex, &$visit, $visitor) {
                     $visitor->onExamineEdge($vertex, $to, $visit);
                     $visit($to);
                 });
                 $visitor->onFinishVertex($vertex, $visit);
                 $visiting->detach($vertex);
                 $visited->attach($vertex);
             }
         }
     };
     while (!$queue->isEmpty()) {
         $vertex = $queue->shift();
         $visit($vertex);
     }
     $visitor->endTraversal();
 }
Пример #27
0
 /**
  * Look for the node in the list and remove it
  *
  * @param Node $node
  */
 public function removeChild(Node $node)
 {
     foreach ($this->children as $key => $child) {
         if ($child !== $node) {
             continue;
         }
         $this->children->offsetUnset($key);
         break;
     }
 }
Пример #28
0
 /**
  * Returns the number or items in this collection
  *
  * @return int
  */
 public function count()
 {
     if (!$this->_started) {
         $this->rewind();
     }
     while ($this->valid()) {
         $this->next();
     }
     return $this->_buffer->count();
 }
 /**
  * {@inheritdoc}
  */
 public function mergeSets($x, $y)
 {
     $setx = $this->findSet($x);
     $sety = $this->findSet($y);
     if ($setx === Null || $sety === Null) {
         return;
     }
     // create a new linked list from both sets
     $setxy = new SplDoublyLinkedList();
     foreach ($this->_sets[$x] as $e) {
         $setxy->push($e);
     }
     foreach ($this->_sets[$y] as $e) {
         $setxy->push($e);
     }
     unset($this->_sets[$x]);
     unset($this->_sets[$y]);
     $this->_sets[$x] = $setxy;
 }
Пример #30
0
function test(SplDoublyLinkedList $l)
{
    $l->push("a");
    $l->push("b");
    $l->push("c");
    echo "Foreach:", PHP_EOL;
    foreach ($l as $key => $val) {
        echo $key, '=>', $val, PHP_EOL;
    }
    echo PHP_EOL;
    echo "ArrayAccess:", PHP_EOL;
    var_dump($l[0]);
    var_dump($l[1]);
    var_dump($l[2]);
    echo PHP_EOL;
    echo "ArrayAccess Set:", PHP_EOL;
    $l[2] = "two";
    var_dump($l[2]);
    try {
        $l[3] = "five";
        // 3 would be the next element
    } catch (OutOfRangeException $e) {
        echo "OutOfRangeException caught", PHP_EOL;
    }
    echo PHP_EOL;
    echo "ArrayAccess Exists:", PHP_EOL;
    var_dump(isset($l[0]), isset($l[2]), isset($l[3]));
    // true, true, false
    echo PHP_EOL;
    echo "ArrayAccess Unset:", PHP_EOL;
    unset($l[0]);
    var_dump($l->offsetGet(0));
    echo PHP_EOL;
    echo "Foreach:", PHP_EOL;
    foreach ($l as $key => $val) {
        echo $key, '=>', $val, PHP_EOL;
    }
    echo PHP_EOL;
}