How do I merge references to objects?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    How do I merge references to objects?

    Hi,

    I'm using PHP 5. I have

    $this->m_pages_arr = array_merge($th is->m_pages_arr, $p_file_obj-
    >m_page_objs_ar r);
    in which "$this->m_pages_arr" is an array and $p_file_obj is an object
    I defined. What I would like is to merge references to objects in the
    "$p_file_ob j->m_page_objs_ar r" array instead of copies of objects,
    which seems to be what is happening now.

    Any advice on how to merge the references? Maybe array_merge is not
    the right function?

    Thanks, - Dave
  • petersprc

    #2
    Re: How do I merge references to objects?

    array_merge shouldn't clone the objects. In most cases, it would be
    necessary to invoke clone directly to do that.

    On May 27, 12:29 pm, "laredotorn...@ zipmail.com"
    <laredotorn...@ zipmail.comwrot e:
    Hi,
    >
    I'm using PHP 5. I have
    >
    $this->m_pages_arr = array_merge($th is->m_pages_arr, $p_file_obj-
    >
    m_page_objs_arr );
    >
    in which "$this->m_pages_arr" is an array and $p_file_obj is an object
    I defined. What I would like is to merge references to objects in the
    "$p_file_ob j->m_page_objs_ar r" array instead of copies of objects,
    which seems to be what is happening now.
    >
    Any advice on how to merge the references? Maybe array_merge is not
    the right function?
    >
    Thanks, - Dave

    Comment

    • Rik Wasmus

      #3
      Re: How do I merge references to objects?

      On Tue, 27 May 2008 22:42:41 +0200, petersprc <petersprc@gmai l.comwrote:
      On May 27, 12:29 pm, "laredotorn...@ zipmail.com"
      <laredotorn...@ zipmail.comwrot e:
      >Hi,
      >>
      >I'm using PHP 5. I have
      >>
      >$this->m_pages_arr = array_merge($th is->m_pages_arr, $p_file_obj-
      >>
      >m_page_objs_ar r);
      >>
      >in which "$this->m_pages_arr" is an array and $p_file_obj is an object
      >I defined. What I would like is to merge references to objects in the
      >"$p_file_ob j->m_page_objs_ar r" array instead of copies of objects,
      >which seems to be what is happening now.
      >>
      >Any advice on how to merge the references? Maybe array_merge is not
      >the right function?
      array_merge shouldn't clone the objects. In most cases, it would be
      necessary to invoke clone directly to do that.
      Unless in PHP < 5, in which case, AFAIK, you'd have to take the long way
      around: foreach'ing, use only the key, make a reference, etc.
      --
      Rik Wasmus
      ....spamrun finished

      Comment

      • petersprc

        #4
        Re: How do I merge references to objects?

        On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
        Unless in PHP < 5, in which case, AFAIK, you'd have to take the long way
        around: foreach'ing, use only the key, make a reference, etc.
        --
        Rik Wasmus
        He's using PHP5, but yeah in previous versions you would certainly do
        that.

        Comment

        • Paul Lautman

          #5
          Re: How do I merge references to objects?

          petersprc wrote:
          On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
          >Unless in PHP < 5, in which case, AFAIK, you'd have to take the long
          >way around: foreach'ing, use only the key, make a reference, etc.
          >--
          >Rik Wasmus
          >
          He's using PHP5, but yeah in previous versions you would certainly do
          that.
          Sheesh, hell must have frozen over, John Peters didn't top post!


          Comment

          • charlescronin@yahoo.com

            #6
            Re: How do I merge references to objects?

            Paul Lautman's 3 most recent posts to c.l.php:

            On May 28, 1:32 pm, Paul Lautman wrote:
            My ones have a bath once a year, whether they
            need it or not!
            On May 28, 11:03 am, Paul Lautman wrote:
            But Elves can catch terrible bugs!
            On May 28, 8:57 am, Paul Lautman wrote:
            Do the words, stubborn, argumentative prat mean
            anything to you?
            Perhaps hell will freeze over when Paul Lautman posts something on
            topic.

            Chuck

            [Top-posted for her pleasure.]

            On May 28, 5:36 pm, "Paul Lautman" <paul.laut...@b tinternet.com>
            wrote:
            petersprc wrote:
            On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
            Unless in PHP < 5, in which case, AFAIK, you'd have to take the long
            way around: foreach'ing, use only the key, make a reference, etc.
            --
            Rik Wasmus
            >
            He's using PHP5, but yeah in previous versions you would certainly do
            that.
            >
            Sheesh, hell must have frozen over, John Peters didn't top post!

            Comment

            • Captain Paralytic

              #7
              Re: How do I merge references to objects?

              On 28 May, 23:27, charlescro...@y ahoo.com wrote:
              Paul Lautman's 3 most recent posts to c.l.php:
              >
              On May 28, 1:32 pm, Paul Lautman wrote:
              >
              My ones have a bath once a year, whether they
              need it or not!
              >
              On May 28, 11:03 am, Paul Lautman wrote:
              >
              But Elves can catch terrible bugs!
              >
              On May 28, 8:57 am, Paul Lautman wrote:
              >
              Do the words, stubborn, argumentative prat mean
              anything to you?
              >
              Perhaps hell will freeze over when Paul Lautman posts something on
              topic.
              Must have frozen over many times by now then.

              Comment

              Working...