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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:57:24+00:00 2026-05-26T14:57:24+00:00

GOAL: Declare/set variables in the scope of the function that called the running function.

  • 0

GOAL: Declare/set variables in the scope of the function that called the running function.

DETAILS:
Hey Overflowans,

I’m looking to add one last little piece of sugar to a utility that I use in a lot of my php functions. It allows me to define a flexible contract on the input of my functions. Over a few iterations, I’ve gotten it pared down to a usage that looks like this:

function doSomething($param_arr){
    FPX::contract(array(
        'required' => array("length", "width", "height", "weight"),
        'optional' => array("circumference")
    ));
    $length = $parr['length'];
    $width = $parr['width'];
    $height = $parr['height'];
    $weight = $parr['weight'];
    $circumference = $parr['circumference'];
    ....
}

FPX::contract() automatically grabs the $param_arr and parses it to make sure that it’s compatible with the defined contract.

What I would like to do now is eliminate the need to declare each of the variables afterwards. Is there a way that I can, within the lowest function, declare variables in the scope of the function that called it? So FPX::contract() needs to be able to set variables that are in the scope of doSomething() so that I don’t have to declare each of these variables. (I don’t want to declare globals).

Ideally it would just look like:

function doSomething($param_arr){
        FPX::contract(array(
            'required' => array("length", "width", "height", "weight"),
            'optional' => array("circumference")
        ));
    ....
}

And then doSomething() would be able to access each of the variables listed in the contract as $length, $width, etc.

I’m aware of the function($var0, $var1, $var2=null) syntax, but it’s not very easy to use this syntax with a large number of optional variables.

Thanks,
Ken

  • 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-26T14:57:25+00:00Added an answer on May 26, 2026 at 2:57 pm

    Maybe you can do something with extract()?

    That is, just have your contract() return an array or a reference to an array, then extract() it.

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

Sidebar

Related Questions

Goal Pass images generated by one process efficiently and at very high speed to
my goal is to write a stored proc that can collect all field values
I'd like to be able to declare a Java class Ref such that I
I have a table called Schedule that serves as a queue mechanism for multiple
Is there a way to declare a private property in Objective C? The goal
My Goal: Is to move data from one table to another if the row
Goal Java client for Yahoo's HotJobs Resumé Search REST API . Background I'm used
Goal: Create Photomosaics programmatically using .NET and C#. Main reason I'd like to do
Goal: to programmatically determine the sizes (in bytes) of the fields of a class.
goal: I have the string 1234432144 I want to only replace the first 2

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.