includes

nonexisting
existing without <?php ...
out('in e15incNoPhP file =', __file__); ... nach existing without <?php
existing with <?php
in e15incWithPhP var = !isset , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incWithPhp
embed 0 => e15incWithPhp in function
embed 1 => e15incZwei in function
mv out1 renamed e15incWithPhp to e15incWithPhpRename
mv out1 renamed e15incZwei to e15incZweiRename
ii=iiDrei
in e15incWithPhP var = 0eins * included e15incWithPhp , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incWithPhp
mv inFun: e15incWithPhp does not exist
in e15incWithPhP var = 0zwei * included e15incWithPhp , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incWithPhp
mv inFun: e15incWithPhp does not exist
the second function fn[1] does the include only here not above as fn[0]!
mv inFun: e15incZwei does not exist
mv out2 renamed e15incZweiRename to e15incZwei
in e15incZwei var = 1vier * included e15incZwei , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incZwei
mv inFun renamed e15incZwei to e15incZweiRename
in e15incZwei var = 1fuenf * included e15incZwei , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incZwei
mv inFun: e15incZwei does not exist
in e15incWithPhP var = 0sechs * included e15incWithPhp , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incWithPhp
mv inFun: e15incWithPhp does not exist
in e15incZwei var = 1sieben * included e15incZwei , file = /home/ch45859/web/wlkl.ch/public_html/inf/php/e15incZwei
mv inFun: e15incZwei does not exist
mv out3 renamed e15incWithPhpRename to e15incWithPhp
mv out3 renamed e15incZweiRename to e15incZwei

gen php

genX j=0 var=call 0 after 0 => null
ea5incF0.php * gen=null * var=call 0 after 0 => null
genX j=0 var=call 0 after 1 => eins
ea5incF0.php * gen=eins * var=call 0 after 1 => eins
genX j=1 var=call 1 after 1 => eins
ea5incF1.php * gen=eins * var=call 1 after 1 => eins
genX j=0 var=call 0 after 2 => zwei
ea5incF0.php * gen=zwei * var=call 0 after 2 => zwei
genX j=1 var=call 1 after 2 => zwei
ea5incF1.php * gen=zwei * var=call 1 after 2 => zwei
genX j=2 var=call 2 after 2 => zwei
ea5incF2.php * gen=zwei * var=call 2 after 2 => zwei
genX j=0 var=call 0 after 3 => drei
ea5incF0.php * gen=drei * var=call 0 after 3 => drei
genX j=1 var=call 1 after 3 => drei
ea5incF1.php * gen=drei * var=call 1 after 3 => drei
genX j=2 var=call 2 after 3 => drei
ea5incF2.php * gen=drei * var=call 2 after 3 => drei
genX j=3 var=call 3 after 3 => drei
ea5incF3.php * gen=drei * var=call 3 after 3 => drei
genX j=0 var=call 0 after 4 => vier
ea5incF0.php * gen=vier * var=call 0 after 4 => vier
genX j=1 var=call 1 after 4 => vier
ea5incF1.php * gen=vier * var=call 1 after 4 => vier
genX j=2 var=call 2 after 4 => vier
ea5incF2.php * gen=vier * var=call 2 after 4 => vier
genX j=3 var=call 3 after 4 => vier
ea5incF3.php * gen=vier * var=call 3 after 4 => vier
genX j=4 var=call 4 after 4 => vier
ea5incF4.php * gen=vier * var=call 4 after 4 => vier
fromInc res 1 , err null , out=vor php 1 in e15incFF.php vor php 2 e15incFF.php echo after <?php, fAdd= [call $f fuenf, call $f fuenf b] , r= [$r add sechs]
...returns [vor php 1 in e15incFF.php, vor php 2, e15incFF.php echo after <?php, call $f fuenf, call $f fuenf b, $r add sechs]
error fromInc(e15Missing) [type => 2, message => include(): Failed opening 'e15Missing' for inclusion (include_path='.:/usr/share/php'), file => /home/ch45859/web/wlkl.ch/public_html/inf/php/e15inc.php, line => 74] , out= , fAdd= [] , r= []
error fromInc(e15incSyntax.php) caught ParseError syntax error, unexpected token "else", expecting end of file , out= , fAdd= [] , r= []

End e15inc.php

args

e15inc.php

/home/ch45859/web/wlkl.ch/public_html/inf/php/e15inc.php

*** code does not have a span berfore first <br>***
<?php

require_once('env.php');
outBegin('includes');
out('nonexisting');
include 'e15incNotExist';
out('existing without &lt;?php ... ');
include 'e15incNoPhp';
out(' ... nach existing without &lt;?php');
out('existing with &lt;?php');
include 'e15incWithPhp';

foreach ( $incs = ['e15incWithPhp', 'e15incZwei'] as $k => $ii) {
    out("embed $k => $ii in function");
    $fn[$k] = function($var) use ($ii) { 
        $var .= " * included $ii"; 
        include $ii;
        mv($ii, "{$ii}Rename", "inFun");
    };
}

foreach ( $incs = ['e15incWithPhp', 'e15incZwei'] as $k => $ii) 
    mv($ii, $ii . 'Rename', 'out1');
$ii = 'iiDrei';
out("ii=$ii");
$fn[0]('0eins');
$fn[0]('0zwei');
out("the second function fn[1] does the include only here not above as fn[0]!");
$fn[1]('1drei');

mv($incs[1] . 'Rename', $incs[1], 'out2');
$fn[1]('1vier');
$fn[1]('1fuenf');
$fn[0]('0sechs');
$fn[1]('1sieben');

foreach ( $incs as $k => $ii)
    mv("{$ii}Rename", $ii, "out3") ;

outH('gen php');
foreach(['null', 'eins', 'zwei', 'drei', 'vier'] as $k => $v) {
    gen($k, $v);
    for ($j=0; $j <= $k; $j++)
        genX($j, "call $j after $k => $v");
} 

fromInc('e15incFF.php');
fromInc('e15Missing');
fromInc('e15incSyntax.php');

outEnd(__file__);

function gen($k, $t) {
    for ($i=0 ; $i<5; $i++) {
        file_put_contents("e15incF$i.php", "<?php\nout(\"ea5incF$i.php * gen=$t * var=\$var\");");
    }
}

function genX($j, $var) {
    out("genX j=$j var=$var");
    include "e15incF$j.php" ;
}

function fromInc($nm) {
    $r = $fAdd = [];
    $f = function() use (&$fAdd) { 
        for($x=0; $x < func_num_args(); $x++)
            $fAdd[] = func_get_arg($x);
    };
    error_clear_last();
    ob_start();
    try {
        $res = @(include $nm);
        $err = error_get_last();
    } catch (Throwable $thr) {
    }
    $out = ob_get_contents();
    ob_end_clean();
    if (isset($thr))
        return out("error fromInc($nm) caught", get_class($thr), $thr->getMessage(), ', out=', $out, ", fAdd=", $fAdd, ", r=", $r);
    if (! $res or $err !== null)
        return out("error fromInc($nm)", $err, ', out=', $out, ", fAdd=", $fAdd, ", r=", $r);
    out("fromInc res", $res, ", err", $err, ", out=$out, fAdd=", $fAdd, ", r=", $r);
    $o = array_merge(explode("\n", $out), $fAdd, $r);
    $o = array_filter($o, function($s) {return $s !== '' and $s[0] !== '#'; });
    out('...returns', $o);        
    return $o;
}

function mv($fr, $to, $m) {
    if (! file_exists($fr)) 
        out("mv $m: $fr does not exist");
    elseif (rename($fr, $to))
        out("mv $m renamed $fr to $to");
    else
        out("mv $m could not rename $fr");
}