2

I am receiving a strange fatal error with the Zend framework when trying to use the Translate class, it appears to try to load an empty file name (.php) which is ending in a fatal error.

Below is the stack trace

[error] [client 79.160.197.135] PHP Warning:  include_once() [<a href='function.include'>function.include</a>]: Failed opening '.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /usr/share/php/Zend/Loader.php on line 146, referer: index.php
[error] [client 79.160.197.135] PHP Stack trace:, referer: index.php
[error] [client 79.160.197.135] PHP   1. {main}() /doc/index.php:0, referer: index.php
[error] [client 79.160.197.135] PHP   2. Zend_Translate->__construct() /doc/index.php:19, referer: index.php
[error] [client 79.160.197.135] PHP   3. Zend_Translate->setAdapter() /usr/share/php/Zend/Translate.php:89, referer: index.php
[error] [client 79.160.197.135] PHP   4. Zend_Loader::loadClass() /usr/share/php/Zend/Translate.php:127, referer: index.php
[error] [client 79.160.197.135] PHP   5. Zend_Loader::loadFile() /usr/share/php/Zend/Loader.php:94, referer: index.php
[error] [client 79.160.197.135] PHP Fatal error:  Uncaught exception 'Zend_Exception' with message 'File ".php" does not exist or class "" was not found in the file' in /usr/share/php/Zend/Loader.php:99

And as a reference, the way I am calling the zend translate class is as follows

<?php

    require_once( 'Zend/Loader.php' );

    Zend_Loader::loadClass( 'Zend_Translate' );

    $translate = new Zend_Translate(
        array(
            'gettext',
            'locale',
            null,
            array('scan' => Zend_Translate::LOCALE_DIRECTORY)
        )
    );
?>

the $translate section is the one calling the class causing the crash.

Clorith
  • 459
  • 1
  • 6
  • 16
  • You somehow did manage to make zend loader load a file for an empty classname. Whatever you did, this does not look good for zend. – hakre Aug 06 '12 at 10:49
  • This is odd, as it's a stock install of the zend framework using aptitud on debian, and everything is pretty much copied off the example from their websites. It would appear this has to be a bug with the loadClass function if anything then... – Clorith Aug 06 '12 at 11:33
  • Yeah, this looks like a fail within the library on input sanitization. Or something is even broken interally in that library so that the class name becomes missing. Have you tried to go in there with a step-debugger? – hakre Aug 06 '12 at 11:36

2 Answers2

2

Turns out the documentation on the Zend site is either too new, or too old for the Zend Framework included with Aptitude on debian.

The Zend_Translate should not be called with a single array, but with individual elements as follows:

$translate = new Zend_Translate( 'gettext', 'path/to/locale.mo', 'locale' );
Clorith
  • 459
  • 1
  • 6
  • 16
0

Depending on what ZF version you are using, you are using the old (deprecated) autoloader.

You could also try:

require_once( 'Zend/Loader/Autoloader.php' );

Zend_Loader_Autoloader::getInstance();

The first time you load the autoloader by calling getInstance(), ZF will automatically register the autoloader. It doesn't solve your problem thought but is just a suggestion.

If you want to create a new Zend_Translate object, you can pass an array for config, but you have to use key => value pairs when specifying the options.

$translate = new Zend_Translate(
        array(
                'adapter' => 'gettext',
                'content' => 'path/to/locale.mo',
                'locale'  => 'en_US',
                'scan'    => Zend_Translate::LOCALE_DIRECTORY
        )
);
drew010
  • 68,777
  • 11
  • 134
  • 162