Is there a way to achieve the following in PHP, or is it simply not allowed? (See commented line below)
function outside() {
$variable = 'some value';
inside();
}
function inside() {
// is it possible to access $variable here without passing it as an argument?
}
Its not possible. If
$variableis a global variable you could have access it byglobalkeyword. But this is in a function. So you can not access it.It can be achieved by setting a global variable by
$GLOBALSarray though. But again, you are utilizing the global context.