Error on page.update:after

Hi, I’m upgrading to the latest version (3.42) but I’m having an error on the page.update:after hook. The error is the following:

Exception: Error
Call to a member function template() on null

The weird thing is that I’m having this error only on the update:after event, while others event seem to run correctly (the first hook in the code below).

Any hint?

'hooks' => [

 //Scrive su db l'articolo una volta aggiornato  
 //---------------------------------------------
'page.update:after' => function ($newpage, $oldpage) {
      
    if($newpage->template() == "article") 
    {
        //Aggiorna l'articolo su db
        articleUpdate($newpage);
    }
    elseif ($newpage->template() == "selezione")
    {
        //Aggiorna la selezione
        saveSelezioneToDB($newpage);
    }
    elseif ($newpage->template() == "longform-plist")
    {
        //Aggiorna l'id del longform playlist
        updateArtSpecialID($newpage);
    }
  }, 


 //Scrive su db l'articolo quando cambio titolo  
 //---------------------------------------------
'page.changeTitle:after' => function ($page,$oldpage) {
      
    if($page->template() == "article") 
    {
        //Articoli
        articleUpdate($page);
    }
    elseif ($page->template() == "selezione")
    {
        //Liste
        saveSelezioneToDB($page);
    }
  },

  //Quando cambia il path di un longform playlist, 
  //viene cambiato il path di tutti gli articoli che ne fanno parte
  //---------------------------------------------------------------
  'page.changeSlug:after' => function ($page,$oldpage) {

      if($page->template() == "longform-plist") articleListMove($page);

  },


  //Scrive lo stato della pagina quando passa da invisibile a visibile
  //------------------------------------------------------------------
  'page.changeStatus:after' => function ($page,$oldpage) {
      
      if($page->template() == "article") 
      {
          //Articoli
          articleUpdate($page);
      }
      elseif ($page->template() == "selezione")
      {
          //Liste
          saveSelezioneToDB($page);
      }
  },


  //Elimina un articolo dal db quando viene eliminato dal panel
  //-----------------------------------------------------------
  'page.delete:after' => function ($status, $page) {

    if($page->template() == "article") 
    {
      deleteArticleFromDb($page);
    }
    else if ($page->template() == "selezione")
    {
      deleteSelezioneFromDb($page);
    }

  },


  //Impedisce il salvataggio di alcune specifiche pagine a chi non ha i permessi
  //-----------------------------------------------------------

  'page.update:before' => function ($page, $values, $strings) {
      
    //if ($page->template() == 'lungo') 
    //{
        //Exception
        //throw new Exception('Non hai i permessi!');
    //}
  }

]
];

After 3.4, you have to use the parameter names in the hooks exactly.

For example:

Your hook:

'page.changeTitle:after' => function ($page, $oldpage) {

Should be:

'page.changeTitle:after' => function ($newPage, $oldPage) {

Hooks documentation

There is @lukasbestle migration tool about this. You can check your hooks using this tool.

Migration Tool

3.4.0 Release Notes

@ahmetbora thank you!

I read the release notes regarding hooks in 3.4.2. I wonder why to pass $newPage and $oldPage as arguments, as they are automagically available as fixed parameters.

Fixed parameters were before 3.4. After 3.4, the wildcard feature came to the hooks. Now you can use it in a wider scope. So we had to convert the hook parameters to the associative array.

You can find more detailed documentation here about wildcard usage: