Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What practical idea could be behind such a function?

Tags:

function

php

I found this function in some script and couldn't get what is the use of it:

    class DemoController extends Controller {

        public function indexAction() {

          $content = include('../index.php');
          return array ('content' => $content);
    }
}

What is the use to include PHP script into variable? Is it a kind of a design pattern? Can anyone drive to the right direction?

like image 747
mixa_ru Avatar asked May 04 '15 09:05

mixa_ru


1 Answers

My guess is that index.php is building up the markup for the page, and then returning it. This is a nice clean way to generate the markup and include it as a string in whatever script may want to use it.

See: http://php.net/manual/en/function.include.php#example-158

like image 58
Sean Johnson Avatar answered Sep 21 '22 00:09

Sean Johnson