Re: References to a variable and scope
| From: | Cesar D. Rodas | Date: | Tue, 04 Dec 2007 21:21:30 +0000 |
| Subject: | Re: References to a variable and scope | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-265456@lists.php.net to get a copy of this message | ||
On 04/12/2007, Cesar D. Rodas <saddor@gmail.com> wrote:
>
> Robert,
>
> On 04/12/2007, Robert Cummings <robert@interjinn.com> wrote:
> >
> > On Tue, 2007-12-04 at 16:58 -0400, Cesar D. Rodas wrote:
> > > Hello,
> > >
> > > 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" */
> >
> > Your code is broken:
>
>
> I knew that, that was a pseudo code. I've try something similar but
> doesn't work.
>
> <?php
> >
> > function foo( &$a )
> > {
> > $GLOBALS['references']['a'] = &$a; /*references to $a */
> > }
> >
> > function bar()
> > {
> > echo $GLOBALS['references']['a'];
> > }
> >
> > $var="hello"
> > foo($var);
> > $var = "hi";
> > bar(); /* it should print "hi" instead of "hello" */
> >
> > ?>
> >
> > Cheers,
> > Rob.
> > --
> > ...........................................................
> > SwarmBuy.com - http://www.swarmbuy.com
> >
> > Leveraging the buying power of the masses!
> > ...........................................................
> >
>
>
> What you code is working, I am so happy for that... the references of a
> reference works,
> thank you! :-)
>
> --
> Best Regards
>
> Cesar D. Rodas
> http://www.cesarodas.com
> http://www.thyphp.com
> http://www.phpajax.org
> Phone: +595-961-974165
--
Best Regards
Cesar D. Rodas
http://www.cesarodas.com
http://www.thyphp.com
http://www.phpajax.org
Phone: +595-961-974165