Getting following error while compilation using this command : php bin/magento setup:di:compile after upgrade Magento 2.1.7 to 2.1.9 check below error for more information :

Warning: ltrim() expects parameter 1 to be string, array given in /MagentoRoot/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/BackslashTrim.php on line 61


I would assume this is related to (read/write/execute) to var and pub directory.

sudo chmod -R 777 var pub

Also try clearing the cache

sudo rm -rf var/cache/* var/generation/*

However it might be something to do with the di folder, this might also work:

  1. Delete the di folder from the var directory
  2. sudo php bin/magento setup:di:compile
  3. Reset file permissions.
  • I have already tried this lots of times. but getting error every time. – Aasim Goriya Oct 2 '17 at 11:02
  • delete vendor and reinstall. Have you tried this ? – andy jones Oct 2 '17 at 11:10
  • FYI site is working fine but compilation not working. Also can you please tell me what needs to be reinstall ? – Aasim Goriya Oct 2 '17 at 11:14

I found this problem solution the from following link https://github.com/magento/magento2/issues/8803

solutions is,

<type name="VENDOR\MODULE\Model\Test">
        <argument name="factories"  xsi:type="array">
            <item name="0" xsi:type="object">VENDOR\MODULE\Model\Somemodel</item>
            <item name="1" xsi:type="object">VENDOR\MODULE\Model\OtherModel</item>

I needed to change enumeration on array starting from 1 instead of 0 to fix it.

Now challenge is , How to find this XML content ( di.xml ) from the Project?

to find it in following file, /MagentoRoot/setup/src/Magento/Setup/Module/Di/Compiler/Config/Chain/BackslashTrim.php

I added logging code as follows,

private function resolveArguments(&$argument)
        if (!is_array($argument)) {

        foreach ($argument as $key => &$value) {
            if (in_array($key, ['_i_', '_ins_'])) {

                if (!is_array($value)) {
                    $value = ltrim($value, '\\');

                    // added logging code
                    $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/test.log');
                    $logger = new \Zend\Log\Logger();
                    $logger->info('Your text message');

                    //You can also print PHP objects and arrays like below :
                    $logger->info(print_r($value, true));


            if (is_array($value)) {

This code print logging code located at /var/log folder when we run back bin/magento setup:di:compile

From log file i got $value variable value Mirasvit\Event\EventData\Condition\Product\Newest for my case issue inside Mirasvit company module EventData.

then from "EventData" module i found this path in di.xml and change enumeration starting from 1 to resolved it

Hope it help


Issue fixed after run following commands in root directory

644 permission for files

find . -type f -exec chmod 644 {} \;

755 permission for directory

find . -type d -exec chmod 755 {} \;

777 permission for var folder

find ./var -type d -exec chmod 777 {} \;

And following commands for pub/media and pub/static

find ./pub/media -type d -exec chmod 777 {} \;

find ./pub/static -type d -exec chmod 777 {} \;

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.