I want to divide the code I have written into smaller manageable files. One file has over 2500 lines and I think it might be better to put some of its code into a separate header file. However, as soon as I separate the code and run it. I get the following error:
Uncaught Error: Class 'Document' not found
Here is the code of my large-file.php
:
<?php
require_once("common-head.php");
/* Some more code */
$document = new Document($document_html);
Here is the code of my common-head.php
:
<?php
/* Some code */
require_once('vendor/autoload.php');
use DiDom\Document;
/* Some more code */
Both the files are located in the same directory so the path to vendor/autoload.php
does not change. However, if the code is placed in separate files as I have shown above, I get the error:
Uncaught Error: Class 'Document' not found
If I take all the code out of common-head.php
and place it in my large-file.php
in place of require_once("common-head.php");
. It works without any error. How can I resolve this issue?