2

I upgraded my site to PHP 7 and now get this error on the frontend:

Warning: Declaration of Works_Walker::start_el(&$output, $category, $depth, $args) should be compatible with Walker_Category::start_el(&$output, $category, $depth = 0, $args = Array, $id = 0)

The code that this refers to is:

 class Works_Walker extends Walker_Category {
 function start_el(&$output, $category, $depth, $args) 

When I edit this code to match the parent I get a syntax error.

class Works_Walker extends Walker_Category {
function start_el(&$output, $category, $depth = 0, $args = Array, $id = 0)

The "Array" seems to be the cause of the syntax error. I hope this is helpful info for a diagnosis.

user3612498
  • 147
  • 1
  • 4
  • 14
  • It tells you right in the message. Your function signature must match the interface/function signature you're extending. This includes "default" values. – noahnu Feb 02 '17 at 23:04
  • Possible duplicate of [Declaration of Methods should be Compatible with Parent Methods in PHP](http://stackoverflow.com/questions/3115388/declaration-of-methods-should-be-compatible-with-parent-methods-in-php) – noahnu Feb 02 '17 at 23:10
  • Thanks for the link and explanation. Unfortunately I can't find any code reference in my site to Walker_Category other than the code I posted earlier. I'm not sure where I can change these signatures to match them. – user3612498 Feb 02 '17 at 23:16
  • You're extending Walker Category and overriding a parent method. To properly override it, your signature must match. Since I presume you don't want to change the parent, you must change the child. – noahnu Feb 02 '17 at 23:19
  • I tried to change the child function to the same as the parent but I get a syntax error. Not sure why that is the case. – user3612498 Feb 02 '17 at 23:32
  • I can't help without knowing the syntax error and how you changed it. You could update the question, although it might now be a bit out of scope of the original problem. – noahnu Feb 03 '17 at 02:02
  • I've edited the post, let me know if that is helpful. – user3612498 Feb 03 '17 at 02:19

1 Answers1

3

Array is a type. You're looking for array() (or []), since you're assigning a default value. I.e. $args = Array should be $args = array(). For reference: 4.7.2/Walker_Category

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
noahnu
  • 3,479
  • 2
  • 18
  • 40