My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

In PHP, can we use a global variable and local variable in the same scope together?

Ankur Singh's photo
Ankur Singh
·Jun 1, 2019

Is it possible to use a global variable and local variable (with the same name) in the same scope? Suppose we have,

<?php
include "example.php";
function foo($bar) {
    global $bar;
    ------------
    ------------
}
?>

How can we access both $bar (global and local) in the same scope, is there any way?