flolam Posted February 27, 2011 Share Posted February 27, 2011 Hi I have a problem with the following: <?php class ClassA { public $propertyClassName = "ClassB"; public function methodClassName() { return "ClassB"; } } class ClassB { public function bmethod() { echo "great!"; } } //works $a = new ClassA(); $b = new $a->propertyClassName(); $b->bmethod(); //doesn't work $a = new ClassA(); $b = new $a->methodClassName(); $b->bmethod(); ?> Of course I could do <?php $a = new ClassA(); $className = $a->methodClassName(); $b = new $className; $b->bmethod(); ?> but isn't there a way to do this without saving the method's return to a variable? Thanks in advance flolam Quote Link to comment Share on other sites More sharing options...
trq Posted February 27, 2011 Share Posted February 27, 2011 public function methodClassName() { return new ClassB; } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.