Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an alternative to die?

Tags:

php

Sorry for the dramatic sounding title, just wanted to know if there is a way to prevent all types of PHP commands from executing EXCEPT one.

For example, now when I kill a script using die() my pages look half broken because the bottom part of the page's html failed to load since it was being brought in using the include() function.

So is there a way to tell PHP "don't allow any more commands to be executed except the include function" ?

like image 929
TJDeatwiler Avatar asked Jan 15 '11 02:01

TJDeatwiler


1 Answers

You can use return to "terminate" an included file, without killing the whole script:

test1.php

<?php
include 'test2.php';
echo 'foo';

test2.php

<?php
echo 'bar';
return;
echo 'baz';

Outputs:

barfoo
like image 129
netcoder Avatar answered Oct 13 '22 20:10

netcoder