include_once
Last updated
What is include_once?
The include_once statement is a part of PHP's file-handling toolkit, allowing developers to include a PHP file within another PHP file, but only for a one-time execution. This way, you can ensure that functions or objects defined in the included file are not duplicated leading to errors. It helps keep your code DRY (Don't Repeat Yourself) and clean. Here is a small example:
include_once 'database.php';
$db = new Database();
In this simple code snippet, we include the database.php file once, giving us access to the Database class.
Free resources to learn include_once
- Official docsinclude_once
More in stage 8: Form Processing
include_once: common questions
Can I learn include_once in Hindi?
This lesson is written in English. Once you sign in, open it in the interactive course and ask the AI tutor to explain include_once in Hindi or Hinglish. The tutor answers from this lesson’s own text, so it stays on the syllabus, and it runs on your own Google, OpenAI or Anthropic key.
Is this include_once tutorial for beginners?
It is lesson 45 of 120 in the free PHP roadmap, in stage 8, Form Processing. If you are new to PHP, start from stage 1 and come back here in order; if you already know the earlier stages, this lesson stands on its own.