Author Topic: Error: Call to a member function register_hook() on a non-object  (Read 4404 times)

Offline snugge

  • Newbie
  • *
  • Posts: 2
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?


Offline SKaero

  • Administrator
  • Hero Member
  • *****
  • Posts: 5,876
    • SKaero - Custom Roundcube development
Re: Error: Call to a member function register_hook() on a non-object
« Reply #1 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.

Offline alec

  • Hero Member
  • *****
  • Posts: 1,363
Re: Error: Call to a member function register_hook() on a non-object
« Reply #2 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.

Offline snugge

  • Newbie
  • *
  • Posts: 2
Re: Error: Call to a member function register_hook() on a non-object
« Reply #3 on: March 22, 2013, 08:25:31 AM »
Thanks alec, the method name was the problem.

(oh god how I loathe OO)