Advertisement
gareth126

example 2 - lesson 2

Nov 14th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Cupboard
  4. {
  5.     public function in($item){
  6.         $this->items[] = $item;
  7.         return $this;
  8.     }
  9.    
  10.     public function out($value){
  11.         $tmpArray = array();
  12.         foreach($this->items as $item){
  13.             if ($item !== $value){
  14.                 $tmpArray[] = $item;
  15.             }
  16.         }
  17.         $this->items = $tmpArray;
  18.         return $this;
  19.     }
  20.    
  21.     public function show(){
  22.         $itemsCurrent = '';
  23.         foreach ($this->items as $item){
  24.             $itemsCurrent .= $item . PHP_EOL;
  25.         }
  26.         return $itemsCurrent;
  27.     }
  28. }
  29.  
  30.  
  31. function __autoload($name) {
  32.     throw new Exception("Unable to load $name.");
  33.     $path = str_replace("_", "/", $name);
  34.     require_once $path.".php";
  35. }
  36. try {
  37.     $obj = new NonLoadableClass();
  38. } catch (Exception $e) {
  39.     echo $e->getMessage(), "\n";
  40. }
  41.  
  42. $cupboard = new Cupboard;
  43.  
  44. $value = $cupboard->in('one')
  45.                   ->in('two')
  46.                   ->out('five')
  47.                   ->show();
  48.                  
  49. echo $value;
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement