[Koha-bugs] [Bug 15759] Allow Koha::Object derived objects to be used as hashrefs

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Thu Jul 7 13:30:31 CEST 2016


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=15759

Alex Sassmannshausen <alex.sassmannshausen at ptfs-europe.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |alex.sassmannshausen at ptfs-e
                   |                            |urope.com

--- Comment #4 from Alex Sassmannshausen <alex.sassmannshausen at ptfs-europe.com> ---
(In reply to Kyle M Hall from comment #1)
> Created attachment 47740 [details] [review]
> Bug 15759 - Allow Koha::Object derived objects to be used as hashrefs
> 
> On occasion, bugs in Koha have been revealed to be a mis-use of
> Koha::Object. This seems to be due to our long standing use of hashrefs
> for data in Koha.
> 
> For instance, a developer may accidentally write:
> 
> my $borrowernumber = $borrower->{borrowernumber};
> 
> instead of
> 
> my $borrowernumber = $borrower->borrowernumber;
> 
> Since our object is a blessed hashref, this does not cause an error.
> Instead, we just access that key of the hashref, which is almost
> certainly undefined.

I can see the problem here, but I am not sure about the proposed
solution.  I think the above should cause an error when it happens,
rather than Koha trying to hide the error.

> With some extra code in Koha/Object.pm, we can allow hashref-like use of
> our Objects, which will not only prevent these errors, but allow drop-in
> use of Koha::Objects where we currently use hashrefs!

To aid code legibility, it makes sense IMHO, to be clear about what we
are using.  The proposed change, while convenient, would obscure.

In terms of the conversion to Koha::Objects, I think it is better to
continue trudging through refactoring as we go.  It's work that needs
to be done anyway, and this is a good opportunity!

Alex

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list