Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
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'.
-
@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". -
Konsole31216y@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...? -
@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 🤔
-
@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.
-
@kolaente Exceptions are almost as evil as gotos though, and only exist because of flaws in the type system.
Related Rants
Found this gem on a website.
I don't know what it means but certainly seemed devRant material
joke/meme
php
website
error