Reputation: 3215
I am learning OOP techniques, so please don't be too harsh if my question sounds too basic ^_^ I have 4 php files.
index.php
parentClass.php
childClass1.php
childClass2.php
childClass1.php and childClass2.php basically extend the parentClass.php. So my question is does the index.php file call the parentClass twice if I include or require both child classes in the index file? For example something like:
require_once("childClass1.php");
$child1 = new childClass1();
require_once("childClass2.php");
$child2 = new childClass2();
Upvotes: 0
Views: 123
Reputation: 32701
It depends on how parentClass.php
is loaded.
Unless you use require_once
or include_once
the file will be included multiple times, which in return will lead to a Fatal Error, as each class may only be defined once.
If you are using an autoloader the file will only be included once, as it will only load unknown classes.
Upvotes: 5