How to exclude a file after including it in php?

After adding the file inside Myfile.phpwith:

require_once 'abc.php';

or

include_once 'abc.php';

How do we delete the file? Or how to stop access to the contents of a file abc.phpafter a certain block of code?

+4
source share
3 answers

In PHP, when a resource is enabled, it cannot be deleted or "not included." This is the very principle of including a PHP file. See: http://www.php.net/manual/en/function.include.php

The include statement includes and evaluates the specified file.

, . , , , . , MyClass, , , . . .

, , PHP 5.3 . , unset. . .

- , .

- , . namespaces. , , .

: . , Symfony , ( ). , , ( , ).

+10

. .

+2

There is a workaround. You can include the file while the output buffer is on. Then save the output in a variable as $ output. Use this if you would otherwise drop it, just don't set ($ output);

ob_start();
include('file.php'); 
$content = ob_get_contents();
ob_end_clean();

And later you can do unset('output')it when you don’t need it anymore.

0
source

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


All Articles