question about using $this as a method in a function argument
| From: | jonathan | Date: | Fri, 20 Jan 2006 22:48:28 +0000 |
| Subject: | question about using $this as a method in a function argument | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-228988@lists.php.net to get a copy of this message | ||
I have a question about using $this as an argument in a method.
I have a simple class called privatemsg and have another data class which it cals for doing the actual insert. Basically, I want the privatemsg class to pass itself as a parameter. I thought using self would do it but nothing seemed to happen. I passed $this as the arg (and am using type-hinting on the privatemsg_data class) and it works. To be totally honest, I have never used $this way and it looks a little strange / inelegant. Should I be doing this another way? Ultimately, I'd like to use a Domain / Mapper model but even then when I look at examples, I see that this takes place.
thanks,
jonathan
class PrivateMsg{
private $msg_recipient_id;
private $headline;
private $body;
//removed get's / set's for brevity
public function insertPrivateMsg()
{
$privatemsg_data=new Privatemsg_Data();
$privatemsg_data->insertMsg($this);
}