1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Call to a member function on null

Discussion in 'Development' started by David, Jul 11, 2020.

  1. David

    David Creeper

    Messages:
    2
    Ok so I know the solution to this should be a check if the player is online or just an instanceof Player. However I still get errors like these throughout numerous spots in my plugin.

    For example...
    PHP:
    $event->getDamager();
    Sometimes when this is called as the damager is logged or logs out, it throws me an error like shown in the title, it returns as null.

    What confuses me is I always have checks before using these functions? Which brings me to my question, how can I avoid getting these errors?
     
  2. Rim

    Rim Spider Jockey

    Messages:
    28
    GitHub:
    boomyourbang
    If the error reads like "call to a member function getDamager() on null", then that means there's no event object.
     
  3. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.