(Edit) Ok the question and the example of what you are trying to accomplish are confusing.
It seems from your example you are trying to DEFINE a class inside another class.
The correct name for this is NESTED CLASS and it is not possible in PHP.
So, to your example the answer is "NO". Not in PHP anyway. Other languages will allow "nested classes". Java is an example.
For example this will NOT work in PHP
class outer_class{
class inner_class{
...
}
...
}
Now the question asked is to create AN INSTANCE of a class in another class.
To this the answer is "YES", you can INSTANTIATE an "object" inside a "class". We do it all the time.
class simple_class{
protected $instanceOfOtherClass;
public function instanciateObject_KeepingAReferenceToIt(){
// create an instance of OtherClass and associate it to $this->instanceOfOtherClass
$this->instanceOfOtherClass = new OtherClass();
}
public function instanciateObject_Without_KeepingAReferenceToIt(){
// create an instance of OtherClass and return it
return new OtherClass();
}
}
A class can even instantiate itself. That's what the famous singleton does and many other Creational patterns. Sadly some people believe that knowing about dependency injection means they will never call NEW in a method again. WRONG.
It helps to understand the difference between a class and an object.
A class is an extensible program-code-template for creating objects.
An object refers to a particular instance of a class.