Inclusion violation

If you want to omit the remaining loop, write a break statement.

Is there something you can write to omit the remaining included file (but not stop the rest of the application, for example, when using dieor exit)?

+3
source share
2 answers

You can use the operator returnto exit the included file and optionally return a value.

Example:

<?php
// file1.php:

$value = include('file2.php');
echo $value;

Including:

<?php
// file2.php:
if($_REQUEST['something'] == 'something else')
  return 'Something else';

//do some stuff if _REQUEST['something'] != 'something else'

return 'something';

Obviously, this is a useless example, but it demonstrates use returnfor the include()ed file .

+7
source

, , , , , , - .

+1

Source: https://habr.com/ru/post/1786733/


All Articles