Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop php processing file

Tags:

php

Is there any way to make php stop processing a file and make it just work with the part it already parsed. I mean like this:

<some data here>
<?php phpinfo(); [IS THERE ANY THING I CAN PUT HERE] ?>
<more data>
[IS THERE ANY THING I CAN PUT HERE]
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

is there anyway to make php ignore data after the first php part?

like image 429
Jones Kamok Avatar asked Dec 01 '09 02:12

Jones Kamok


1 Answers

Another solution might be to use __halt_compiler :

Halts the execution of the compiler. This can be useful to embed data in PHP scripts, like the installation files.

Byte position of the data start can be determined by the __COMPILER_HALT_OFFSET__ constant which is defined only if there is a __halt_compiler() presented in the file.

A typical usage is for Phar archives, when you need to embed PHP and (possibly binary) data into a single file, and the PHP code needs to have access to that data.


And there is actually a difference : this code :

blah blah
<?php phpinfo(); ?>
glop glop
<?php exit(); ?>
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

Gets me a Parse error: syntax error, unexpected T_STRING
(Probably because I have short_open_tag enabled, I suppose)


While this one :

blah blah
<?php phpinfo(); ?>
glop glop
<?php __halt_compiler(); ?>
<?HOW CAN I MAKE PHP NOT PARSE THIS?>

works OK -- this invalid PHP code being after the call to __halt_compiler().

like image 145
Pascal MARTIN Avatar answered Sep 18 '22 13:09

Pascal MARTIN