When should I use require_once vs. require?

Technology CommunityCategory: PHPWhen should I use require_once vs. require?
VietMX Staff asked 4 years ago

The require_once() statement is identical to require() except PHP will check if the file has already been included, and if so, not include (require) it again.

My suggestion is to just use require_once 99.9% of the time.

Using require or include instead implies that your code is not reusable elsewhere, i.e. that the scripts you’re pulling in actually execute code instead of making available a class or some function libraries.