Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

reverse function of require/include

Tags:

php

Is there any function that reverts a require/require_once/include/include_once?

For instance in script A I need to require a script B which has common functions with other script C and I don't know if previously C was required or not. So I would like to "clean" script C from memory before loading B preventing duplicated functions.

like image 797
javier_domenech Avatar asked May 23 '26 16:05

javier_domenech


1 Answers

You can not - and should not do that. Instead use require_once - it will be safe for such operations. Note, that after inclusion your context will be changed - so no way to "reverse" it back could be applied.

If you want to override some functionality - you can always do that, it will work normally. And you should check things before declaring them:

  • function_exists() for functions
  • class_exists() for classes
  • (optional) defined() for constants
like image 55
Alma Do Avatar answered May 25 '26 04:05

Alma Do



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!