Roundcube Community Forum

Third Party Contributions => API Based Plugins => Topic started by: snugge on March 21, 2013, 10:45:01 PM

Title: Error: Call to a member function register_hook() on a non-object
Post by: snugge on March 21, 2013, 10:45:01 PM
Hi,

I'm trying to write a simple plug-in for logging sent mail, and i'm not even getting it to register its hooks...

code:
(plugins/log_sent_mail/log_sent_mail.php)

<?php
class log_sent_mail extends rcube_plugin
{
  public $task = 'mail';
  public $noajax = true;
  public $noframe = true;

  function init() {
    $this->add_hook('message_sent', array($this, 'log_sent_mail'));
  }

  function log_sent_mail($arg) {
    write_log('debug','sent mail');
  }
}
?>


I just get this error:
 PHP Fatal error:  Call to a member function register_hook() on a non-object in /var/www/roundcubemail-0.9-rc/program/lib/Roundcube/rcube_plugin.php on line 130

are the docs at http://trac.roundcube.net/wiki/Doc_Plugins correct?

Title: Re: Error: Call to a member function register_hook() on a non-object
Post by: SKaero on March 22, 2013, 01:11:48 AM
I believe this is the bug thats causing the problem: http://trac.roundcube.net/ticket/1488941 Its fixed in the git master.
Title: Re: Error: Call to a member function register_hook() on a non-object
Post by: alec on March 22, 2013, 04:53:32 AM
class log_sent_mail extends rcube_plugin
{
  function log_sent_mail($arg) {
You have a method with the same name as the class name. They can't be the same.
Title: Re: Error: Call to a member function register_hook() on a non-object
Post by: snugge on March 22, 2013, 08:25:31 AM
Thanks alec, the method name was the problem.

(oh god how I loathe OO)