Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //file: Classes/Cupboard.php
- class Cupboard
- {
- protected $_items;
- public function addItem($item)
- {
- $this->_items[] = $item;
- return $this;
- }
- public function removeItem($item)
- {
- $key = array_search($item, $this->_items);
- unset ($this->_items[$key]);
- return $this;
- }
- public function listItems()
- {
- return implode(', ', $this->_items);
- }
- }
- <?php
- // file: Run.php
- function __autoload($class)
- {
- $path = dirname(__FILE__) . '/Classes';
- $classFile = $path . '/' . ucfirst(strtolower($class)) . '.php';
- if (!file_exists($classFile)) {
- throw new InvalidArgumentException('Non-existing class provided');
- }
- require_once $classFile;
- }
- $cb = new Cupboard();
- echo $cb->addItem('plate')
- ->addItem('cup')
- ->addItem('spoon')
- ->addItem('fork')
- ->removeItem('spoon')
- ->listItems() . PHP_EOL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement