Jump to content

Recommended Posts

Well i've scoured the PHP.net documentation and Google'd this thoroughly and can't find anything, which suggests it is impossible but I thought I should get a collective opinion on it.

 

So we all know what preg_match() is, its third argument (in most examples is $matches) becomes available to the rest of the script calling that function.

 

What I want to be able to do is say I have a function called foo with the argument $bar I want the variable $bar to become available throughout the rest of my script. Like below.

 

//I don't want to have to do this
function foo()
{
       return 'Foobar!';
}
$bar = foo();//outputs Foobar!

//but rather do this
function foo($bar)
{
       return $bar = 'Foobar!';
}
echo $bar;//I want it to output Foobar! but doesn't 

 

I've tried quite a few thigns now and can't seem to work it out naturally, anyone have any suggestions?

Ooops my bad, this was simple :s Basically (just to explain) the function assigning the variable is member of a class which is instantiated by another class and returned (for method chaining) and this seemed like a good feature to have so the method chaining wasn't made redundant by having to separate lines for variable assignment. I set the inner class to accept by reference but not the controller  :shrug:

 

All fixed now :)

 

Thanks anyways guys :)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.