In our staging area, I added a new extension and the developers have had to do some work to get a few features working properly. Now that the backend features are working properly, I went to load the product on the frontend and got this error:

Fatal error: Cannot redeclare formatHex() (previously declared in ~/app/design/frontend/neighborhood/default/template/notificationbar/notificationbar-header.phtml:19) in ~/app/design/frontend/neighborhood/default/template/notificationbar/notificationbar-header.phtml on line 21

The code sitting between lines 19 - 21 looks like this:

function formatHex($value) { 
    return "#" . str_replace('#', '', $value);

If I disable the extension completely, flush the cache, then reload the page - I'm given a completely different error with a SQL call and files relating to the new extension.

Any pushes in the right direction are appreciated. I have already tried removing lines 19-21 - the page will load but only the "notificationbar" area, everywhere after is blank.

1 Answer 1


I think you've done a conceptual mistake. There's no way / need to have a function declared in a template .phtml file.

In your magento, this function seems to be declared twice, and when you load the page the function is probably crafted twice, with the same function name. In this case, without using classes/namespaces for example, this is not allowed by php.

You should consider at least :

  • writting a magento module that act as a Helper
  • copy/paste the function in there
  • browse all you /app/design/frontend/* code
  • remove same functions found
  • alter the code where formatHex() is used to use Helper function instead

This can help you creating the helper Creating a custom helper class in module

Hope this helps !

  • Thank you for your response @ffab - the .phtml file came from an extension we repurposed and had a 3rd party developer work on to suit our needs. Since posting this, the new extension's developer has resolved the issue and I am waiting to hear what the fix was.
    – Steven J
    Commented Mar 9, 2017 at 17:01
  • would be great if you can leave some words here to explain a bit more. i'm glad that the issue is resolved for you. cheers
    – ffab
    Commented Mar 10, 2017 at 21:21
  • Developer resolved the issue, but did not remove the original call in the existing extension. Still in discussion over how to properly implement so the issue does not arise again in the future.
    – Steven J
    Commented Mar 20, 2017 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.