PHP, Zend, require_once: “failed to open stream” a

2019-09-04 07:01发布

I'm going nuts! I've been SO'ing and Googling for 2 hours now.

In short, things were working fine, and then I did some class-restructuring, and now I'm getting this:

    Warning: require_once(Zend/Mail/Transport/Sendmail.php) [function.require-once]: failed to open stream: No such file or directory in /nfs/c09/h02/mnt/136160/domains/xyz.com/html/sandbox/Zend/Mail.php on line 1175

    Fatal error: require_once() [function.require]: Failed opening required 'Zend/Mail/Transport/Sendmail.php' (include_path='.:/usr/local/php-5.3.13/share/pear') in /nfs/c09/h02/mnt/136160/domains/xyz.com/html/sandbox/Zend/Mail.php on line 1175

I didn't touch how my files were organized:

    sandbox/index.php
    sandbox/settings.php
    sandbox/lib/class1.php
    sandbox/lib/class2.php
    sandbox/lib/class3.php
    sandbox/Zend/...

I only changed some class names and their hierarchy.

index.php

<?php
    require_once 'lib/class1.php';
    $application = new class1();
    $application->run();
?>

class1.php

<?php

    require_once 'Zend/Loader.php';
    Zend_Loader::loadClass('Zend_Log');
    Zend_Loader::loadClass('Zend_Log_Formatter_Simple');
    Zend_Loader::loadClass('Zend_Log_Writer_Mail');
    Zend_Loader::loadClass('Zend_Log_Writer_Stream');
    Zend_Loader::loadClass('Zend_Mail');

    // class definition ...
?>

None of these requires needed to be touched during my class restructuring. The specific issue (although I'm sure there is a more general issue) occurs in Zend's Mail.php:

/**
 * Sends this email using the given transport or a previously
 * set DefaultTransport or the internal mail function if no
 * default transport had been set.
 *
 * @param  Zend_Mail_Transport_Abstract $transport
 * @return Zend_Mail                    Provides fluent interface
 */
public function send($transport = null)
{
    if ($transport === null) {
        if (! self::$_defaultTransport instanceof Zend_Mail_Transport_Abstract) {
            require_once 'Zend/Mail/Transport/Sendmail.php';
            $transport = new Zend_Mail_Transport_Sendmail();
        } else {
            $transport = self::$_defaultTransport;
        }
    }

    ...
}

(Note how the require is called only on the first attempt to send an email.)

  1. Can a new "flow" or order-of-includes possibly cause this issue? (Since the paths seem okay. If the paths weren't okay, it'd die at Loader.php, would it not?)

  2. Can a circular dependency of some kind cause this issue, before it caused a more "fatal" one?

  3. Can a class name possibly conflict with something that already exists? Previously I had some fairly arcane class names like MalaFwk_Application_Receiver. Now, names are more generic, e.g. CApplication, CComponent, CDatabase, CLogger, etc.

I've tried various things suggested in other SO threads to no avail, but I'm willing to try anything anyone suggests. I apologize in advance if this isn't a particularly constructive question, but I'm out of ideas, and there were far too many (trivial but widespread) changes to revert and reapply the changes in pieces. Any help would be greatly appreciated. (I will be back at ~8:45a EST.)

UPDATE:

If I add the following line to index.php, i.e. "manually" require the file before anything else happens, then things work again.

    require_once 'Zend/Mail/Transport/Sendmail.php';

So it appears that, for some reason, by the time the code gets to send(), it can't find the library. What could possibly cause this?

1条回答
劳资没心,怎么记你
2楼-- · 2019-09-04 07:57

Please add this to your index:

set_include_path(implode(PATH_SEPARATOR, array(          
    realpath('../library'), // Make sure this is the correct path to your library folder
    get_include_path(),
)));
查看更多
登录 后发表回答