Pointer in PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • John Downey
    Guest replied
    Re: Pointer in PHP

    Denis Crespe wrote:[color=blue]
    > Hi,
    >
    > Is it possible to keep a pointer to an object in a PHP variable? I'd like to
    > do this :
    >
    > $obj1 = new myClass(...);
    > $obj2 = $obj1;
    > $obj1->name = "foo";
    > $obj2->name = "bar";
    >
    > echo $obj1->name;
    >
    > Which would display "bar" instead of "foo" with the current PHP behavior.
    >
    > Thanks a lot,
    > Denis[/color]
    $obj2 = &$obj1;

    --
    John Downey




    Leave a comment:


  • Denis Crespe
    Guest replied
    Re: Pointer in PHP

    Awesome! It's what I wanted :-)

    Denis

    "rush" <pipa@rush.aval on.hr> a écrit dans le message de news:
    bnh4b3$e4u$1@ls 219.htnet.hr...[color=blue]
    > "Denis Crespe" <a@a.com> wrote in message
    > news:bnh2mc$1p2 $1@news.tiscali .fr...[color=green]
    > > $obj1 = new myClass(...);
    > > $obj2 = $obj1;
    > > $obj1->name = "foo";
    > > $obj2->name = "bar";
    > >
    > > echo $obj1->name;
    > >
    > > Which would display "bar" instead of "foo" with the current PHP[/color][/color]
    behavior.[color=blue]
    >
    > you can not get the pointer, but you can get the reference:
    >
    > $obj2 = & $obj1;
    >
    > rush
    > --
    > http://www.templatetamer.com/
    >
    >
    >[/color]


    Leave a comment:


  • rush
    Guest replied
    Re: Pointer in PHP

    "Denis Crespe" <a@a.com> wrote in message
    news:bnh2mc$1p2 $1@news.tiscali .fr...[color=blue]
    > $obj1 = new myClass(...);
    > $obj2 = $obj1;
    > $obj1->name = "foo";
    > $obj2->name = "bar";
    >
    > echo $obj1->name;
    >
    > Which would display "bar" instead of "foo" with the current PHP behavior.[/color]

    you can not get the pointer, but you can get the reference:

    $obj2 = & $obj1;

    rush
    --
    Get your very own domain easily. Fast and professional customer service.




    Leave a comment:


  • Denis Crespe
    Guest started a topic Pointer in PHP

    Pointer in PHP

    Hi,

    Is it possible to keep a pointer to an object in a PHP variable? I'd like to
    do this :

    $obj1 = new myClass(...);
    $obj2 = $obj1;
    $obj1->name = "foo";
    $obj2->name = "bar";

    echo $obj1->name;

    Which would display "bar" instead of "foo" with the current PHP behavior.

    Thanks a lot,
    Denis




Working...