How can PHP locate a class when extending it within the same file?
When extending a class within the same file in PHP, you can use the `require_once` or `include_once` function to include the file containing the parent class before defining the child class. This ensures that the parent class is loaded and available for inheritance when extending it within the same file.
<?php
// Include the file containing the parent class
require_once 'ParentClass.php';
// Define the parent class
class ParentClass {
// Parent class definition
}
// Define the child class extending the parent class
class ChildClass extends ParentClass {
// Child class definition
}
?>