Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5986911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:44:23+00:00 2026-05-22T22:44:23+00:00

<?php $foo = 1; function meh(){ // <– $foo can’t be accessed } It

  • 0
<?php

$foo = 1;

function meh(){
  // <-- $foo can't be accessed
}

It doesn’t look like a global variable. However, does it have disadvantages like global stuff if it’s outside the function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:44:24+00:00Added an answer on May 22, 2026 at 10:44 pm

    Yes. They can be accessed from any location, including other scripts. They are slightly better as you have to used the global keyword to access them from within a function, which gives more clarity as to where they are coming from and what they do.

    The disadvantages of global variables apply, but this doesn’t instantly make them evil as is often perceived in some OO languages. If they produce a good solution that’s efficient and easily understandable, then you’re fine. There are literally millions of succesful PHP projects that use global variables declared like this. The biggest mistake you can make is not using them and making your code even more complicated when it would have been perfectly fine to use them in the first place. 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you do something like this in PHP: function foo() { super->foo(); // do
In PHP why can't I do: class C { function foo() {} } new
if I call php's parse_ini_file(foo.ini) , in what paths does it look for foo.ini
so simple question! How can I pass a variable into a jQuery function, like
Possible Duplicate: Caller function in PHP 5? Like this: function foo(){ do_something(); } function
If I return nothing explicitly, what does a php function exactly return? function foo()
In this code: <?php class Foo { var $value; function foo($value) { $this->setValue($value); }
Is the following example appropriate for PHP's require_once construct? function foo( $param ) {
Why would PHP allow nesting functions? <?php function foo() { function bar() { return
<?php class a { public function foo() { echo __METHOD__ . PHP_EOL; } }

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.