How can undefined function errors be avoided when including external PHP files?

When including external PHP files, undefined function errors can be avoided by ensuring that the necessary functions are defined before they are called in the main script. This can be achieved by using include_once or require_once to include the external file, which will prevent the file from being included more than once and causing redeclaration issues.

<?php
require_once 'external_functions.php';

// Code that uses the functions from external_functions.php
?>