Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zend_Translate issues 'failed to open stream' warning when using a custom adapter #46

Closed
g10-fred opened this issue Jan 25, 2021 · 4 comments · Fixed by #116
Closed

Comments

@g10-fred
Copy link

Issue is on line 130 of class Zend_Translate, the 'class_exists' function is attempting to autoload a custom adapter as a 'Zend_Translate_Adapter_' and issues a warning when it is not found:

PHP Warning: include_once(Zend/Translate/Adapter/Custom/Translate/Adapter.php): failed to open stream: No such file or directory in /var/www/comm-os/vendor/zf1s/zend-loader/library/Zend/Loader.php on line 134

Requires the 'autoload' parameter of the class_exists function to be set to false.

@glensc
Copy link
Contributor

glensc commented Jan 26, 2021

@g10-fred, no the error comes from Zend/Loader:

You should stop using Zend_Loader and stick with the composer autoloader. The zf1s/zf1 project is intended to use composer autoloader.

@falkenhawk is it covered anywhere how to stop using Zend_Loader?

@falkenhawk
Copy link
Member

falkenhawk commented Jan 27, 2021

@glensc I haven't covered any instructions about moving away from Zend_Loader myself.

However here a reproduction (and/or a stacktrace) from @g10-fred would be great - why it fails, is it a combination of wrong options passed or is it triggered from the zf1 internals somewhere.

Anyway, Requires the 'autoload' parameter of the class_exists function to be set to false. this would not be a solution, as the adapter class is expected to be loaded dynamically with composer, and not preloaded somewhere. We could silence the error with @ eventually, as it is done in other places and let the script proceed instead of triggering a warning.

@g10-fred
Copy link
Author

g10-fred commented Jan 27, 2021

We have simply have a custom Zend_Translate_Adapter class and we pass the name of the class to Zend_Translate in a Controller Plugin.

Something like:
$translate = new Zend_Translate('Custom_Translate_Adapter', array(), $langLocale, $options);

Here's a stack trace:
PHP Warning: include_once(Zend/Translate/Adapter/G10/Translate/Adapter/G10.php): failed to open stream: No such file or directory in /var/www/comm-os/vendor/zf1s/zend-loader/library/Zend/Loader.php on line 134, referer: https://commos-local.gen10.net/
PHP Stack trace:, referer: https://commos-local.gen10.net/
PHP 1. {main}() /var/www/comm-os/public/index.php:0, referer: https://commos-local.gen10.net/
PHP 2. Zend_Application->run() /var/www/comm-os/public/index.php:68, referer: https://commos-local.gen10.net/
PHP 3. Bootstrap->run() /var/www/comm-os/vendor/zf1s/zend-application/library/Zend/Application.php:391, referer: https://commos-local.gen10.net/
PHP 4. Zend_Controller_Front->dispatch($request = uninitialized, $response = uninitialized) /var/www/comm-os/vendor/zf1s/zend-application/library/Zend/Application/Bootstrap/Bootstrap.php:105, referer: https://commos-local.gen10.net/
PHP 5. Zend_Controller_Plugin_Broker->preDispatch($request = uninitialized) /var/www/comm-os/vendor/zf1s/zend-controller/library/Zend/Controller/Front.php:941, referer: https://commos-local.gen10.net/
PHP 6. G10_Controller_Plugin_LangSelector->preDispatch($request = uninitialized) /var/www/comm-os/vendor/zf1s/zend-controller/library/Zend/Controller/Plugin/Broker.php:309, referer: https://commos-local.gen10.net/
PHP 7. Zend_Translate->__construct($options = uninitialized, uninitialized, uninitialized, uninitialized) /var/www/comm-os/vendor/g10/g10-framework/library/G10/Controller/Plugin/LangSelector.php:38, referer: https://commos-local.gen10.net/
PHP 8. Zend_Translate->setAdapter($options = uninitialized) /var/www/comm-os/vendor/zf1s/zend-translate/library/Zend/Translate.php:95, referer: https://commos-local.gen10.net/
PHP 9. class_exists(uninitialized) /var/www/comm-os/vendor/zf1s/zend-translate/library/Zend/Translate.php:130, referer: https://commos-local.gen10.net/
PHP 10. spl_autoload_call(uninitialized) /var/www/comm-os/vendor/zf1s/zend-translate/library/Zend/Translate.php:130, referer: https://commos-local.gen10.net/
PHP 11. Zend_Loader_Autoloader::autoload($class = uninitialized) /var/www/comm-os/vendor/zf1s/zend-translate/library/Zend/Translate.php:130, referer: https://commos-local.gen10.net/
PHP 12. Zend_Loader_Autoloader->_autoload($class = uninitialized) /var/www/comm-os/vendor/zf1s/zend-loader/library/Zend/Loader/Autoloader.php:132, referer: https://commos-local.gen10.net/
PHP 13. Zend_Loader::loadClass($class = uninitialized, $dirs = uninitialized) /var/www/comm-os/vendor/zf1s/zend-loader/library/Zend/Loader/Autoloader.php:487, referer: https://commos-local.gen10.net/
PHP 14. Zend_Loader::loadFile($filename = uninitialized, $dirs = uninitialized, $once = uninitialized) /var/www/comm-os/vendor/zf1s/zend-loader/library/Zend/Loader.php:82, referer: https://commos-local.gen10.net/

@falkenhawk
Copy link
Member

related commit which might have caused this issue 76477fb - logic with class_exists must be changed in such cases so it does not trigger a warning, but also not throw an exception, when Zend_Loader_Autoloader is enabled 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants