exclude php

Solutions on MaxInterview for exclude php by the best coders in the world

showing results for - "exclude php"
Nicolò
04 Feb 2019
1In PHP, once a resource is included, it can not be removed or "un-included". This is the very principle of PHP file inclusion. See : http://www.php.net/manual/en/function.include.php
2
3The include statement includes and evaluates the specified file.
4
5Once the interpreter has evaluated your code, the job is done. All operations have been taken into account, and in order to undo the changes, you have to perform the opposite operations. For instance, if your included file declares the class MyClass then you would need to undefine it, which is also impossible for very same reason as above. See : Unset Class.
6
7If your file actually adds functions and not classes, then since PHP 5.3, you can use anonymous functions. This allows you to assign functions to variables, which can be unset. See this answer for details.
8
9If a part of your code's logic has to disappear at some point, then you did not spend enough time designing before implementing.
10
11If you need to undo an inclusion because of name conflicts, the problem is pretty much the same. However, a solution in this case would be to use namespaces. Still, a little review of your application design should be enough to avoid such conflicts.
12
13Edit about frameworks : a single framework cannot fit for each and every application. Symfony, for instance, uses namespaces absolutely everywhere to avoid any possible conflicts (yet, some occur). If your framework does not offer you the possibility to easily distinguish two model classes with the same name, then I'd say it does not fit (at least, not with your design).