Re: References to a variable and scope
| From: | Richard Lynch | Date: | Thu, 06 Dec 2007 17:18:33 +0000 |
| Subject: | Re: References to a variable and scope | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265519@lists.php.net to get a copy of this message | ||
On Tue, December 4, 2007 2:58 pm, Cesar D. Rodas wrote:
> I know that PHP doesn't support pointers to a variable, instead of
> that
> there is references to a variable which are similar to pointers,
> right?
>
> BTW, what I want to do is to save a references to a variable and read
> the
> content when I need, similar to PDO "bindParam". I will try to explain
> better in the following pseudo php code.
>
> function foo($a) {
> $GLOBALS['references']['a'] = /*references to $a */
> }
>
> function bar() {
> echo $GLOBALS['references']['a'];
> }
>
> $var="hello"
> foo($var);
> $var = "hi";
> bar(); /* it should print "hi" instead of "hello" */
If you are making things this complicated, you will probably regret it
someday...
That said, I think if you just did:
foo('var');
and changed the 'a' in foo/bar to $a
then you would get what you want...
It won't be a reference nor a pointer, but just a global variable,
disguised by using $GLOBALS instead of:
global $var;
as you should do for clarity.
YMMV
--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?