How do I merge references to objects? – PHP

  php

Q(Question):

Hi,

I’m using PHP 5. I have

$this->m_pages_arr = array_merge($this->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_obj->m_page_objs_arr" 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

A(Answer):

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.comwrote:

Hi,

I’m using PHP 5. I have

$this->m_pages_arr = array_merge($this->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_obj->m_page_objs_arr" 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

A(Answer):

On Tue, 27 May 2008 22:42:41 +0200, petersprc <pe*******@gmail.comwrote:

On May 27, 12:29 pm, "laredotorn…@zipmail.com"
<laredotorn…@zipmail.comwrote:

>Hi,

I’m using PHP 5. I have

$this->m_pages_arr = array_merge($this->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_obj->m_page_objs_arr" 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

A(Answer):

On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe…@hotmail.comwrote:

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.

A(Answer):

petersprc wrote:

On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe…@hotmail.comwrote:

>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!

A(Answer):

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…@btinternet.com>
wrote:

petersprc wrote:

On May 27, 7:18 pm, "Rik Wasmus" <luiheidsgoe…@hotmail.comwrote:

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!

A(Answer):

On 28 May, 23:27, charlescro…@yahoo.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.

LEAVE A COMMENT