0

my log is filled up with this warnings:

2016-04-18T07:13:09+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:28+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:28+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:28+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:28+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:42+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:42+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:42+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:42+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:42+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:58+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569
2016-04-18T07:15:58+00:00 ERR (3): Warning: array_key_exists(): The first argument should be either a string or an integer  in /html/magento/app/code/core/Mage/Core/Model/Translate.php on line 569

How can I find the file which calls this function, to solve this warning?

  • 1
    you are probably calling somewhere in the code $this->__($a) where $a is not a string (array maybe, or object). – Marius Apr 18 '16 at 7:48
  • what @Marius said. For example, if it's an XML node, you have to explicitly convert it to string: __((string) $node) – Fabian Schmengler Apr 18 '16 at 7:55
1

Line 569 of core/Mage/Core/Model/Translate.php is:

elseif (array_key_exists($text, $this->getData()))

Which is part of the function

protected function _getTranslatedString($text, $code)

If you use something like phpstorm you should be be to find usages of that function. I'd assume it's a module you have installed in community or local. Something could be overwriting the Mage_Core_Model_Translate

1

Try temporarily putting this in the first line of the _getTranslatedString method in core/Mage/Core/Model/Translate.php

    try {
        if ((!is_string($text) && !is_int($text)) || (!is_string($code) && !is_int($code))) {
            Mage::log(var_export(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), true), null, 'translateError.log', true);
        }
    } catch (Exception $e) {
        Mage::logException($e);
    }

Once you see the warning appear in the logs again, go look at translateError.log for a stack trace of what code called __() and correct the issue. Repeat until you don't get any warnings anymore.

(For me, something was calling if ($this->__('Filter' == 'Category')) instead of if ($this->__('Filter') == 'Category') which resolved to a boolean.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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