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

  • Home
  • SEARCH
  • 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 8390153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:54:40+00:00 2026-06-09T18:54:40+00:00

lest assume that i have the following function a(){ function b(){} } a(); //pass

  • 0

lest assume that i have the following

function a(){
  function b(){}
}
a(); //pass
a(); //error

why in the second call an exception is thrown and it says

cannot re-declare  function b()

i thought that each function call makes a new active record that it contains its own scope ;
like in other languages other that PHP when we declare a variable in a function and called that function all the variables are alive for their scope, why the inner function is not the same ?

  • 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-06-09T18:54:41+00:00Added an answer on June 9, 2026 at 6:54 pm

    Named functions are always global in PHP. You will therefore need to check if function B has already been created:

    function A() {
        if (!function_exists('B')) {
            function B() {}
        }
        B();
    }
    

    A different solution is to use an anonymous function (this will more likely fit your needs, as the function is now stored in a variable and therefore local to the function scope of A):

    function A() {
        $B = function() {};
        $B();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lest say that we have several pages that retrieve items from the same EntitySet.
Lest say i have a link and when some one click on that link
Lest just say i have a movieClip A which contains movieClips B1,B2,B3,B4,B5 I write
I have another class that creates the connection (see refined class half way down
A strange error began occurring in our code in the lest week or two.
I need to call function whenever class is created using new. Currently I need
lest say I have two lists List1: Tom, Frank, Lacey List2: Frank, Tom what
I am trying to test that a particular method throws an expected exception from
Lest's say I have string: String test= "AA BB CC BB BB CC BB";
I have a table witch is in intense workload lest say T1 (about 100

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.