• Resolved scott.hepler

    (@scotthepler)


    We get an occasional error which I can’t track down. Hopefully someone here can help!

    Sometimes, on some browsers (not repeatable or predictable), we get this error in place of a calendar:

    *Catchable fatal error*: Argument 1 passed to
    SimpleCalendar\Events\Event::__construct() must be of the type array,
    object given, called in
    [snip]/wp-content/plugins/google-calendar-events/includes/abstracts/calendar.php
    on line 430 and defined in
    *[snip]/wp-content/plugins/google-calendar-events/includes/events/event.php*
    on line *242*

    Any ideas? It looks like simcal_get_feed must be returning something unexpected (an object of some type in place of an array of some type), but I haven’t dug deeper.

    Thanks,
    Scott

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Nick Young

    (@nickyoung87)

    Hi Scott,

    Are you running any sort of caching plugin? I would try also running through this to see if it helps at all or if you can narrow down the issue: https://docs.simplecalendar.io/troubleshooting-theme-plugin-widget-conflicts/

    Thread Starter scott.hepler

    (@scotthepler)

    Hi Nick:

    Thanks for getting back to us. We are not currently doing any caching. The site is in production, so I’ll need to do the conflict checks later.

    Thanks again,
    Scott

    Thread Starter scott.hepler

    (@scotthepler)

    Hi again, Nick:

    OK, I’ve collected some more info:
    – the (only) calendar which has the issue is a Grouped Calendar which aggregates ~24 smaller calendars
    – we put in some debugging code to see what type of object the original error is complaining about; it turns out to be a __PHP_Incomplete_Class Object that looks like a SimpleCalendar\\Events\\Event — this seems to indicate that the class isn’t loaded
    – I increased the WP memory by 50%, but no change

    Thanks,
    Scott

    Thread Starter scott.hepler

    (@scotthepler)

    OK, we got this squared away ourselves. It’s just a little workaround if $event is an object but not an instance of Event. Add this inside the ‘set_events’ function of includes/abstracts/calendar.php ; this begins at line 423 on v3.1.3. Here’s the patched function:

    
    /**
     * Set events.
     *
     * @since 3.0.0
     *
     * @param array $array
     */
    public function set_events( array $array ) {
    
            $events = array();
    
            if ( ! empty( $array ) ) {
                    foreach ( $array as $tz => $e ) {
                            foreach ( $e as $event ) {
                                    /* for some reason we occasionally see $event show up here as a 
                                    * __PHP_Incomplete_Class Object even though it's formatted properly as 
                                    * an Event object; it's all public variables, so we can simply cast
                                    * to an array and let the next line deal with it
                                    */
                                    if (!($event instanceof Event) && !is_array($event))
                                            $event = (array) $event;
    
                                    $events[ $tz ][] = $event instanceof Event ? $event : new Event( $event );
                            }
                    }
            }
    
            $this->events = $events;
    }
    
    • This reply was modified 8 years, 5 months ago by scott.hepler.
    Plugin Contributor Nick Young

    (@nickyoung87)

    Cool, glad you got it sorted out.

    You can always add this as a Pull Request on our GitHub repo so we can take a look and see if we want to add it in: https://github.com/moonstonemedia/Simple-Calendar/pulls

    Thanks!

    Hi Nick/Scott,

    I was running into this same error as well with grouped calendars. From my testing, it seems like it has something to do with a non-cached access of a calendar. The code on line 114 in grouped-calendars.php returns a Boolean “false”.

    $events = get_transient( '_simple-calendar_feed_id_' . strval( $this->post_id ) . '_' . $this->type );

    This causes line 164 to error since $events is not an Array.

    To fix this, I’ve added the below line right below line 114. By doing this, I did not need to change anything in the calendar.php code.
    if(!$events) $events = array();

    Please let me know if you see any issues with this approach.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘strange sporadic error’ is closed to new replies.