Advertisement
Guest User

PHP 7.1.2 Generator Segfault

a guest
Feb 24th, 2017
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?php
  2. class Test {
  3.     public function run() {
  4.         $this->html = new HtmlHelper();
  5.         $this->test = new TestHelper();
  6.  
  7.         $test = (string)$this->html('main', function() {
  8.             $category = [ 'name' => 'test', 'philosophy' => 'Paragraph about philosophy of working with brands.' ];
  9.  
  10.             for($i = 0; $i < 50; $i++) {
  11.                 yield $this->html('article', function() use($category) {
  12.                     yield $this->html('h3', $category['name']);
  13.                     yield $this->html('div', $this->html->lower($category['philosophy']));
  14.  
  15.                     yield $this->html('div', $this->test('This is a test'));
  16.                     yield $this->test->doThing();
  17.                 });
  18.             }
  19.         });
  20.         die($test);
  21.     }
  22.  
  23.     public function __call($name, $args) {
  24.         $helper = $this->{$name};
  25.         return $helper(...$args);
  26.     }
  27. }
  28.  
  29. class HtmlHelper {
  30.     public function __invoke($name, $content) {
  31.         return '<'.$name.'>'.$this->_renderChild($content).'</'.$name.'>';
  32.     }
  33.  
  34.     protected function _renderChild($value) {
  35.         if(is_callable($value) && is_object($value)) {
  36.             return $this->_renderChild($value($this));
  37.         }
  38.  
  39.         if(is_array($value) || $value instanceof \Generator) {
  40.             $output = '';
  41.  
  42.             foreach($value as $part) {
  43.                 $output .= $this->_renderChild($part);
  44.             }
  45.  
  46.             return $output;
  47.         }
  48.  
  49.         return (string)$value;
  50.     }
  51.  
  52.     public function lower($value) {
  53.         return strtolower($value);
  54.     }
  55. }
  56.  
  57. class TestHelper {
  58.     public function __invoke($value) {
  59.         return strtoupper($value);
  60.     }
  61.  
  62.     public function doThing() {
  63.         return 'other thing';
  64.     }
  65. }
  66.  
  67. (new Test())->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement