php/e21scope.php

<html>
<h2><?php echo basename(__file__); ?> PHP define</h3>
<?php 
require_once('env.php');
outBegin();

function show($h) {
    $all = ['$gA', '$fB', '$fC', 'C::$cSD', '$this->cPE', '$cFSF', '$cMG'];
    $r = "out('$h'); outOL();";
    foreach ($all as $a) 
        $r .= "try { outLi('$a', ! isset($a) ? '--invisible' : 'set = ' . $a);} catch(Throwable \$ex) {outLi('$a', 'catch ', \$ex->getMessage());}";
    return $r . "outOLEnd();";
}
eval(show('main, before decs'));
$gA = 'gA global';
function f() {
    $fB = 'fB in fun f';
    eval(show('in function f after dec'));
    global $gA;
    eval(show('in function f after global'));
    function f2() {
        $fC = 'fC in fun f2 ';
        eval(show('in function f2 (not!) nested in f after dec'));
        global $gA;
        eval(show('in function f2 (not!) nested in f after global'));
    }
}
f();
f2();

class C {
    static $cSD = 'cSD static property of class C';
    public $cPE = 'cPE property of instance of class C';
    # eval(show('in class C'));   no statements allowed here
    static function cFS() {
        $cFSF = 'cFSF in static fun cFS in class C';
        eval(show('in static fun cFS in class C'));
    }
    function cM() {
        $cMG = 'cMFGin in method cM in class C';
        eval(show('in method cM in class C'));
    }
}

C::cFS();
(new C())->cM();
eval(show('main at end'));


outEnd(__file__);
?>