Jump to content

preg_match like global variable possible?


developerdave

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.