What is dynamic inheritance?
aka PHP's hardest to understand concept
apc.report_autofilter=1
Warning: include(): Dynamic inheritance detected for class child2 in /var/www/indexB.php on line 2
Warning: include(): Autofiltering c2.php in /var/www/indexB.php on line 2
Warning: include(): Recompiling /var/www/c2.php in /var/www/indexB.php on line 2
indexA.php
<?php
include 'c1.php';
include 'c2.php';
new Child1;
new Child2;
echo 'Done';
indexB.php
<?php
include 'c2.php';
new Child2;
echo 'Done';
c1.php
<?php
include 'p1.php';
class Child1 extends MyParent {
function __construct() {
parent::__construct();
}
}
c2.php
<?php
if(!class_exists('MyParent')) include 'p2.php';
class Child2 extends MyParent {
function __construct() {
parent::__construct();
}
}
p1.php
<?php
class MyParent {
function __construct() {
echo "Parent1";
}
}
p2.php
<?php
class MyParent {
function __construct() {
echo "Parent2";
}
}
If indexB is hit first
opcodes for c2.php
line # * op fetch ext return operands
---------------------------------------------------------------------------------
2 0 > SEND_VAL 'MyParent'
1 DO_FCALL 1 $0 'class_exists'
2 BOOL_NOT ~1 $0
3 > JMPZ ~1, ->6
4 > INCLUDE_OR_EVAL 'p2.php', INCLUDE
5 > JMP ->6
3 6 > ZEND_FETCH_CLASS :3 'MyParent'
7 ZEND_DECLARE_INHERITED_CLASS '00child22Fvar2Fwww2Fc3.php0x7f7a5af32054', 'child2'
8 8 > RETURN 1
If indexA is hit first
opcodes for c2.php
line # * op fetch ext return operands
-----------------------------------------------------------------------------
2 0 > SEND_VAL 'MyParent'
1 DO_FCALL 1 $0 'class_exists'
2 BOOL_NOT ~1 $0
3 > JMPZ ~1, ->6
4 > INCLUDE_OR_EVAL 'p2.php', INCLUDE
5 > JMP ->6
3 6 > NOP
7 NOP
8 8 > RETURN 1