So I've inherited this weirdly behaving (and horribly tinkered) shop containing some external product and customer import scripts.

One of these scripts ('importcustomer_fields.php', located in the webroot) reads as following (which is structure-wise pretty much the same like the other scripts having the same issue):

Note: The class definition and __construct() and launch() method are pretty much what they are in the actual script, all further methods within do not seem relevant to me for the moment / in this matter


require __DIR__ . '/app/bootstrap.php';


class TestApp extends \Magento\Framework\App\Http implements \Magento\Framework\AppInterface
    protected $customerFactory;
    protected $custgroup;
    protected $addressFactory;
    protected $appState;
    protected $_log;

    public function __construct(\Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Model\AddressFactory $addressFactory,\Magento\Framework\App\ResourceConnection $resource,\Magento\Framework\App\State $appState,\Magento\Customer\Model\ResourceModel\Group\CollectionFactory $custgroup,\Psr\Log\LoggerInterface $logLogger) {

        $this->_log = $logLogger;
        $this->customerFactory = $customerFactory;
        $this->custgroup = $custgroup;
        $this->addressFactory = $addressFactory;
        $this->_resources = $resource;
        $this->appState = $appState;

    public function launch(){

        $dsn = "dsn";
        $user = "username";
        $pw = "password";
        // side note before this gets misinterpreted: ODBC is used to connect to a remote MSSQL-DB not to the Magento-DB

        $connect = odbc_pconnect($dsn, $user, $pw);
        $query = "SELECT x FROM y WHERE z = 'something';"

        $result = odbc_exec($connect, $query);

    public function CreateCustomer($result) {

        while($data = odbc_fetch_array($result)) {
            // ...

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$app = $bootstrap->createApplication('TestApp');

The issue I'm facing here since a short while now is that by the time I re-compile via php bin/magento setup:di:compile that these external scripts stop working, for above given example script with the following error:

Fatal error: Uncaught TypeError: Argument 1 passed to TestApp::__construct() must be an instance of Magento\Customer\Model\CustomerFactory, instance of Magento\Framework\ObjectManager\ObjectManager given, called in /var/www/xyz/web/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php on line 93 and defined in /var/www/xyz/web/importcustomer_fields.php:26 Stack trace: #0 /var/www/xyz/web/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php(93): TestApp->__construct(Object(Magento\Framework\ObjectManager\ObjectManager)) #1 /var/www/xyz/web/vendor/magento/framework/ObjectManager/Factory/Compiled.php(88): Magento\Framework\ObjectManager\Factory\AbstractFactory->createObject('TestApp', Array) #2 /var/www/xyz/web/vendor/magento/framework/ObjectManager/ObjectManager.php(57): Magento\Framework\ObjectManager\Factory\Compiled->create('TestApp', Array) #3 /var/www/xyz/web/vendor/magento/framework/App/Boot in /var/www/xyz/web/importcustomer_fields.php on line 26

Strange enough however, if I remove the directory var/di these scripts are working again (the shop it self does not work anymore, though). So, the general suggestion of clearing all temp data and re-compiling does not seem to work here.

However, I tracked down the issue (or at least it seems so) to the var/di/global.ser file, which, when removed (while the rest of var/di is just the way php bin/magento setup:di:compile would build it) both, the store and the external scripts are working.

But why - and what might be going wrong here (even though the current state seems to be working for the moment it's nothing that I can keep as it is - nor do I know whether there are any parts broken due to the removed global.ser)?

  • I would bet that you have a class that extends the offending class and you didn't update the constructor of the child class. – Shawn Abramson Jan 23 '18 at 18:44

Your Answer

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

Browse other questions tagged or ask your own question.