Is there a better alternative for using two $this-> in the same sentence?
If you do:
$this->$this->name->something();
You wi开发者_如何学Goll surely get an error.
I've been doing something like:
$name =& $this->name;
$this->$name->something();
But is there a better way for doing that? Would it be easier if PHP had some way of doing something like:
$this->'$this->name'->something();
Thanks!
But is there a better way for doing that? Would be easier, if PHP has some way to do, something like: $this->'$this->name'->something();
There is;
$this->{$this->name}->something( );
But... what are you doing? Do you really need this? It seems like an odd construct from where I'm standing.
If $this->name
is an object, then $this->name->something()
should work just fine.
Edit: Note also, if your methods return objects, you can just chain up the method calls:
$this->name->something()->somethingElse()->anotherThing();
精彩评论