Reputation: 1039
I am wondering if PHP will re-use the Parent class. With the following code:
// File parent.php
class Parent {
$public foo = '';
public function __construct($args) {
// ..
}
// .. some functions
}
// File child1.php
class Child1 extends Parent {
public function __construct() {
}
// .. Some overridden function
// .. some extra functions
}
// File child2.php
class Child2 extends Parent {
public function __construct() {
}
// .. some extra functions
}
Now to use either Child1 or Child2 you need to include the parent.php and childN.php. If I only use Child1 I can imagine they are somehow concatenated into a single being. However if I use Child2 on the same page.. would I get 2 'concatenated' beings, that gobble on memory or is PHP super smart and able to see this and only use/load/whatever the Parent only once.
This example is pretty simplified, but the Parent is pretty big and there are plenty of children!
Upvotes: 0
Views: 145
Reputation: 23316
Parent
is loaded only once. In fact, PHP will throw an error if you try to load it twice.
Upvotes: 0
Reputation: 11080
Short answer is "PHP super smart", the memory is only going to be used to store the class instances, the portion of memory to store the class definitions is negligible. You can also worry about number of inclusions, but in this particular case everything is far from slow.
Upvotes: 2