A
A
Anton2018-04-25 19:06:21
PHP
Anton, 2018-04-25 19:06:21

How to fix Fatal error: Cannot redeclare isAnyElementInArray?

Previously, there was one component on the page, then, if necessary, it was necessary to use it several times:
here is a part of the code from the component that caused the error

function isAnyElementInArray($arNeedle, $arHaystack)
{
    foreach ($arNeedle as $curNeedle)
    {
        if (in_array($curNeedle,$arHaystack))
        {
            return $curNeedle;
        }
    }
    return false;
}

The text of the error itself:
Fatal error: Cannot redeclare isAnyElementInArray() (previously declared in /home/bitrix/www/bitrix/templates.........) in /home/bitrix/www/bitrix/templates......... on line 15

Moreover, on the test server where the development was going on, there is no such error, but on the combat one it is.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey, 2018-04-25
@anton99zel

if(!function_exists('isAnyElementInArray')) {
    function isAnyElementInArray($arNeedle, $arHaystack) {}
}

S
Stalker_RED, 2018-04-25
@Stalker_RED

You already have an isAnyElementInArray function and you are trying to declare another one with the same name.
Solutions:
Find where it already exists and use it
Change the name of this new feature
Learn from namespaces

and what does she mean?
Not ashamed? If only the translator drove this message.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question