php include и закрывающий тег

Saw a thread about omitting the closing ?> in PHP scripts and got me wondering.

Take this code:

foo.php

<?php
echo 'This is foo.php';
include('bar.php');

bar.php

<?php   
echo 'This is bar.php';

If you create these two scripts and run them, php outputs:

This is foo.php
This is bar.php

(new line added for artistic license before anyone points that out)

So, how come: baz.php

<?php
echo 'This is foo.php';

<?php
echo 'This is bar.php';

results in a predictable syntax error unexpected '<', when "include" does just that - or rather, my understanding of include is that PHP just dumps the file at that point as if it had always been there.

Does PHP check for opening tags and ignore future ones if the file is included? Why not do this when there are two sets of tags in one script?

Thanks for any clarification. Not exactly an important issue but would be nice to understand PHP a little more.

8
задан Harry Johnston 4 May 2014 в 21:00
поделиться