Is it possible to assign many objects to 1 variable?

is it possible to assign many objects to 1 variable ??

example :

class aaa{
	public $z;

class a{	
	function aa()
			echo "aa";

class b{	
	function bb()
			echo "bb";

$aaa=new aaa();

$aaa->z= new a();
$aaa->z= new b();

//run aa function inside a class;
//run bb function inside b class;

is it posible

Use an array :wink:
$aaa->z = new a();

hi hash , thanks alot , yes i know this , but i want know if it possible to do this idea or no , because i think that i saw like it before in Codeigniter FrameWork before …

You can’t assign two things to one variable, so no; was probably something similar you saw, like

in this case it will be replaced…
may be cloning object (clone() )can come handy if you really needs this…
single variable can hold single value only at a instance thats why we need array

A better question to ask is “why am I trying to do this?”. If you’re in a situation where you need to assign two objects to the same variable, you might want to take a look at your design again, because you’re off path.

It is possible to do what you want, but as others have mentioned it doesn’t seem like something you really want to be doing. Could you maybe elaborate a bit on why you have chosen an approach like this?

i think it can be bcoz of :slight_smile:
1)ignorance during the learning curve…(you know many things later…as u move on)

2)May be he wants to have excat clone of an object (of an instance) at some point in the code or particular point of time (retaining all variables)…
then he want to store 1 copy (may be useful for some operation later)
and perform certain action in its copy (clone) of it…
(for kind of temp storage)

Just a situation i think,it can come handy but even in that as it is said,better designing will eliminate that need…