SectionMagicObjects.php 800 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2017 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. class SectionMagicObjects
  11. {
  12. public $start = 'It worked the first time.';
  13. public function middle()
  14. {
  15. return new MagicObject();
  16. }
  17. public $final = 'Then, surprisingly, it worked the final time.';
  18. }
  19. class MagicObject
  20. {
  21. protected $_data = array(
  22. 'foo' => 'And it worked the second time.',
  23. 'bar' => 'As well as the third.',
  24. );
  25. public function __get($key)
  26. {
  27. return isset($this->_data[$key]) ? $this->_data[$key] : null;
  28. }
  29. public function __isset($key)
  30. {
  31. return isset($this->_data[$key]);
  32. }
  33. }