Psalm: Fatal errors with Zend dependencies

Created on 29 Dec 2017  路  10Comments  路  Source: vimeo/psalm

I'm getting some fatal errors from the vendor directory and I'm not sure how to work around them. When running vendor/bin/psalm --debug:

Fatal error: Trait 'Zend\Db\Adapter\AdapterAwareTrait' not found in vendor/zendframework/zend-validator/src/Db/AbstractDb.php on line 28

Fatal error: Cannot use 'Null' as class name as it is reserved in vendor/zendframework/zend-log/src/Writer/Null.php on line 22

I have tried ignoring these particular files in psalm.xml:

```







````

But I still get the same errors. Any suggestions?

All 10 comments

What version of Psalm is this with?

I was looking at this earlier with @er0k and these are the versions I have:

Psalm 0.3.71@035f528581bcbcad19a2e141016234eb66b2cd14
PHP 7.0.14RC1
zendframework/zend-log 2.9.2
zendframework/zend-validator 2.10.1

Could you try with latest dev-master and see if the error reoccurs? I recently added some extra protections to mitigate fatal errors when reflecting classes in PHP.

Unfortunately, I still received both errors with the dev-master version as well.

Psalm dev-master@875bb8c072ce1228c8f12518f3bf38dc365da5fd

Are you using the regular composer autoloader?

and does the vendor/zendframework/zend-db folder exist?

Yes, standard autoloader.

So zend-db does not exist. In ZF3, the packages were split. ZF seems to have adopted this approach where some classes, like AbstractDB, are broken if you only install one package and not the other. We don't run into issues at run time because we don't use any of the classes that extend AbstractDB.

I was able to reproduce the other error in a bare directory with these commands:

composer require vimeo/psalm:dev-master zendframework/zend-log:2.9.2
mkdir src
.\vendor\bin\psalm --init
.\vendor\bin\psalm --debug .\vendor\zendframework\zend-log\src\WriterPluginManager.php

Ok, I think I understand you now.

The two separate problems are:

  • ZF is require-deving a bunch of packages (like zendframework/zend-db that it should be requireing. That issue is discussed in https://github.com/zendframework/zend-validator/issues/83, but the maintainers take the (IMO wrong) view that it's up to individual devs to take what they want
  • ZF uses Null in a class name, and PHP 7 breaks. It's been addressed in ZF's code so that the only use of it in current code is here (https://github.com/zendframework/zend-log/blob/02620c83d46a61a647ce640803fd154fe1879994/src/WriterPluginManager.php#L39) where PHP won't exit with E_FATAL because ::class constants do not trigger the autoloader. Psalm, however, checks all class constants to ensure that the class actually exists, in some cases triggering the autoloader if the class is in the vendor directory and not mapped in autoload_classmap.php.

The first problem is one for you to take up with the ZF maintainers, and in the meantime require-dev: zendframework/zend-db so that Psalm won't panic on that code.

The second problem can be slightly ameliorated by me 鈥撀營 can prevent Psalm from checking ::class constant class existence when there's a reserved word being used in the class name.

Using the code you provided with latest dev-master, PHP no longer exits with a fatal error.

I think that's all I can do for now, but Psalm can also be better about dealing with reserved words generally (e.g. https://github.com/vimeo/psalm/issues/382).

Thanks for the quick responses and concise reproducible testcase!

Awesome. I tested f81642c and it resolves the zend-log issue. We'll use your suggested work around for the other issue. Thanks so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

staabm picture staabm  路  3Comments

ErikBooijCB picture ErikBooijCB  路  4Comments

vudaltsov picture vudaltsov  路  3Comments

albe picture albe  路  3Comments

ADmad picture ADmad  路  3Comments