[Koha-devel] Proposed coding standard: always check for object existence before use

Barton Chittenden barton at bywatersolutions.com
Wed Jun 13 19:23:59 CEST 2018


Calling a method or accessing a member of an undefined object will throw a
fatal error that looks like this:  "can't call method * on an undefined
value at ..."

For example, this code will cause a software error if $data->{itemnumber}
exists, but the item doesn't exist (maybe it's been deleted?):

my $item = Koha::Items->find( $data->{itemnumber} );
my $biblio = $item->biblio;

How this is handled will of course depend on context -- maybe we should
carp and continue, or maybe just

my $item = Koha::Items->find( $data->{itemnumber} );
my $biblio = $item->biblio if defined $item;

I would like to add a coding standard that we always check for this.

Thanks,

--Barton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20180613/aa8c132b/attachment.html>


More information about the Koha-devel mailing list