freenity Posted September 23, 2007 Share Posted September 23, 2007 Well actually I have 2 classes: class a { private $bb = array(); public function __construct() { for($i=0;$i<3;$i++) $this->bb[] = new b; } public function getb() { return $this->bb; } } class b { public function hello() { echo "hi"; } } the i do: $aa = new a; $aa->getb()[0]->hello(); and yes, it trows an error: Parse error: syntax error, unexpected '[' in D:\XAMPP\xampp\htdocs\test\index.php on line 39 I know that I can just store the value in a variable and then use it to call the function, but isn't it possible to do this? Thanks. Link to comment https://forums.phpfreaks.com/topic/70380-solved-problem-with-agregate-classes/ Share on other sites More sharing options...
emehrkay Posted September 23, 2007 Share Posted September 23, 2007 I am stumped. Like you said, $x = $aa->getb(); $x[0]->hello(); works fine. This is a strange one, maybe it has something to do with the order of execution. What is the reason why you want to use this format instead of setting it to a variable? Link to comment https://forums.phpfreaks.com/topic/70380-solved-problem-with-agregate-classes/#findComment-353561 Share on other sites More sharing options...
freenity Posted September 23, 2007 Author Share Posted September 23, 2007 The only reason of wanting to do this is simplicity Nothing important but I think this can be done in c++ so I thought it should work but.. Link to comment https://forums.phpfreaks.com/topic/70380-solved-problem-with-agregate-classes/#findComment-353565 Share on other sites More sharing options...
Daniel0 Posted September 25, 2007 Share Posted September 25, 2007 Unfortunately, PHP does not support this syntax. There are sometime where I would have liked to do something similar, but it isn't possible. Link to comment https://forums.phpfreaks.com/topic/70380-solved-problem-with-agregate-classes/#findComment-354683 Share on other sites More sharing options...
freenity Posted September 25, 2007 Author Share Posted September 25, 2007 Thanks for the reply. Link to comment https://forums.phpfreaks.com/topic/70380-solved-problem-with-agregate-classes/#findComment-355025 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.