# "Call to a member function on array" when using hooks in Plugin

**URL:** <https://forum.getkirby.com/t/call-to-a-member-function-on-array-when-using-hooks-in-plugin/17889>\
**Category:** Questions\
**Tags:** v3\
**Created:** [April 15, 2020, 10:18am UTC](https://forum.getkirby.com/t/call-to-a-member-function-on-array-when-using-hooks-in-plugin/17889 "2020-04-15T10:18:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bruno](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bruno/32/6422_2.png) [@bruno](https://forum.getkirby.com/u/bruno)\
**Post date:** [April 15, 2020, 10:18am UTC](https://forum.getkirby.com/t/call-to-a-member-function-on-array-when-using-hooks-in-plugin/17889/1 "2020-04-15T10:18:48Z")

</div>

I’m using the `kirby-color` plugin for a site i’m working on. It is generating hex values, but I need to use RGBA at a point on my site, so I want to call a function to generate an RGBA value whenever the field is changed. I’m getting the error “Call to a member function backgroundColor() on array” in the panel. My plugin looks like this:

```auto
Kirby::plugin('bruno/hex2rgba', [
    'hooks' => [
      'site.update:before' => function ($site, $oldSite) {
        $oldHex = $oldSite->backgroundColor()->value();
        $newHex = $site->backgroundColor()->value();
            if($oldHex !== $newHex) {
                $site->update(array(
                    'backgroundColorRGBA' => hex2rgba($site->backgroundColor()->value()),
                ));
            }
      }
    ]
]);

```

Does it not work to access `site` & `oldsite` the same way that you can use `page` and `oldpage` in the hook?

> **[Hooks](https://getkirby.com/docs/reference/plugins/extensions/hooks#error-handling)**

---

<div class="post-metadata">

**Author:** ![bruno](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bruno/32/6422_2.png) [@bruno](https://forum.getkirby.com/u/bruno)\
**Post date:** [April 15, 2020, 10:22am UTC](https://forum.getkirby.com/t/call-to-a-member-function-on-array-when-using-hooks-in-plugin/17889/2 "2020-04-15T10:22:42Z")

</div>

… The error was my use of a `:before` hook instead of `:after`.
