mixa_ru
mixa_ru

Reputation: 603

What practical idea could be behind such a function?

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?

Upvotes: 5

Views: 81

Answers (1)

Sean Johnson
Sean Johnson

Reputation: 5607

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

Upvotes: 5

Related Questions