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 8518233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:55:29+00:00 2026-06-11T05:55:29+00:00

The title may be a bit confusing, so let me explain. I have a

  • 0

The title may be a bit confusing, so let me explain. I have a class and a method. That that method itself has a function. Like this:

class MyClass {
   public static function my_function($param) {
      function nested_function() {
        //do something with $param
      }
   }
}

So my question is, how can I access $param in nested_function?

EDIT

The reason I’m doing this is because of a wordpress thing. I need something like this:

class MyClass {
   public static function my_function($param) {
      function nested_function() {
        //do something with $param
      }

      add_action('init', 'nested_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-06-11T05:55:31+00:00Added an answer on June 11, 2026 at 5:55 am

    This is not a sensible thing to do. All named functions in PHP are global. Nesting them inside something else just makes their declaration conditional. I.e. you cannot call nested_function until you have called MyClass::my_function. And afterwards you cannot call MyClass::my_function again, because PHP will try to redeclare an existing function.

    Maybe you want a closure, i.e. an anonymous function, which can include variables from the parent scope:

    public static function my_function($param) {
        $nested_function = function () use ($param) {
            //do something with $param
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The title may have been confusing, but please let me explain: Currently when I
That title may need some work. Perhaps after reading this, you may be able
The title of this question may be a bit misleading. I couldn't quite think
The title may be a bit vague. This is what I mean: Say I
Possible Duplicate: UITextField focus the title may be a bit confusing.. couldn't figure out
This title may sound a little bit crazy, but this is what is making
My title may be a bit unclear so I'll try to explain a bit
The title may be a bit vague, but here's my goal: I have a
The title may be bit confusing but here is what I am facing I
I realize that title is a bit vague, so let me try and clear

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.