8
Konsole
5y

Found this gem on a website.
I don't know what it means but certainly seemed devRant material

Comments
  • 3
    hook(null);

    Hahahah
  • 2
    That looks like someone doesn't know how to properly set up wordpress.
  • 3
    Seriously though, the error means the hook() method (which most likely is part of a class) was called before the class itself has been initialized. Which makes this kind of the 'null pointer exception of php'.
  • 1
    @kolaente

    It's super common in PHP. You perform a call which returns what other languages would call a "maybe" or "option", for example some "findById" method to get a user. If the user doesn't exist, you might get a null.

    Well placed "?Type" hints and an IDE like phpstorm can help catch most null pointer exceptions. But no matter what, with PHP you're quite dependent on tools and developer discipline to catch them.

    Better languages like Haskell and Rust force you to handle these, by wrapping all nullable values in a "maybe monad".
  • 0
    @zemaitis

    Isn't this null.hook()?
  • 1
    @kolaente @bittersweet
    I have never done php, but is it not a bad idea to echo server errors to frontend?
    I have used Django heavily and it just shows server error and puts the error in logs.
    Maybe I am missing something...?
  • 1
    @xkill yes of course it is. Usually these are disabled for production deploys and only enabled for development. But it could be they're enabled by default 🤔
  • 1
    @bittersweet I would throw an exception and catch it when I select a user which doesn't exist. Then I'm forced to deal with it and won't call other methods on that user object.
  • 0
    @kolaente Exceptions are almost as evil as gotos though, and only exist because of flaws in the type system.
Add Comment