Support » Fixing WordPress » Illegal Offset Type when using wp_schedule_event

  • Resolved Wes

    (@therealwesfoster)


    When I try creating a schedule, I get an “Illegal Offset” error in /wp-includes/cron.php on line 79. Since I didn’t edit the core cron.php file, I’m not sure what’s wrong. Here’s my code that calls the function:

    <?php
    class ClassName {
    
    // This function runs instantly when the class is called
    function __construct(){
       $start_date = strtotime('27 September 2011');
       wp_schedule_event($start_date, 'hourly', array(&$this, 'do_cron'));
    }
    
    // The cron data
    function do_cron(){
       die('The cron data is here!');
    }
    
    }// end class
    
    // Run the class
    $class = new ClassName();
    ?>

    And just in case you don’t want to look, line 79 of cron.php is:

    $crons[$event->timestamp][$event->hook][$key] = array( 'schedule' => $event->schedule, 'args' => $event->args, 'interval' => $event->interval );

    Any ideas? I’m stumped!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Wes

    (@therealwesfoster)

    Could it be that I’m putting an array in place of the (string) $hook?

    In most functions, you can add array(&$this, ‘function_name’) in place of the hook to call a function from the same class. However, the schedule functions specifically call for a “string” instead of a string|array.

    I bet this is the problem. I’ll try it now and come back with an answer if it’s working.

    Wes

    (@therealwesfoster)

    That is EXACTLY the problem! Hopefully this post will help someone else!

    This needs to be fixed in the next version of WP though, for sure.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Illegal Offset Type when using wp_schedule_event’ is closed to new replies.