Scope

The scope is the context in which a variable is defined. A variable scope is usually its host method, or the file in which is used. It also extends to any included files, and skips other method definition.

Arrow functions are initialised with the same scope than the defining scope, but do not write back in it. Closure with the use keyword also import variables from the defining scope.

Scopes are generally considered as global or local.

<?php

// $a is defined in the file scope
$a = 1;

// $a is extended to the included scope
include 'b.php';

// arrow functions use the same scope than the defining code.
// here, $a is also defined there.
// $c will not be available in the calling scope.
$c = fn () => $a + ($c = 2);

function foo() {
     // $b is only defined in the foo() function
     echo $b;
}
?>

Documentation

Related : Local Scope, global Scope