PHP,Zend,require_once:“无法打开流”和“无法打开所需的” [英] PHP, Zend, require_once: "failed to open stream" and "Failed opening required [...]"

查看:1106
本文介绍了PHP,Zend,require_once:“无法打开流”和“无法打开所需的”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我疯了!我一直在搜索和谷歌搜索2个小时。

总之,事情工作正常,然后我做了一些班级重组,现在我' m得到这个:
$ b

 警告:require_once(Zend / Mail / Transport / Sendmail.php)[function.require-once]:未能打开流:没有这样的文件或目录在/nfs/c09/h02/mnt/136160/domains/xyz.com/html/sandbox/Zend/Mail.php 1175行

致命错误:require_once()[function.require]:在/ nfs /中打开所需的'Zend / Mail / Transport / Sendmail.php'(include_path ='。:/ usr / local / php-5.3.13 / share / pear'在线1175


$ b上的c09 / h02 / mnt / 136160 / domains / xyz.com / html / sandbox / Zend / Mail.php $ b

我没有碰到我的文件如何组织:

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

I只改变了一些类名和它们的层次结构。
$ b $ p 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');

//类定义...
?>

这些 require都不需要在我班改组时感动。在Zend的 Mail.php 中出现了一个具体的问题(虽然我确信存在一个更普遍的问题):

  / ** 
*如果没有设置
*默认传输,则使用给定的传输或以前的
*设置DefaultTransport或内部邮件函数发送此电子邮件。
*
* @param Zend_Mail_Transport_Abstract $ transport
* @return Zend_Mail提供流畅的界面
* /
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;




$ b code $


(请注意,只有在第一次尝试发送电子邮件时, require 才会被调用。)


  1. 一个新的flow或者order-of-include可能会导致这个问题吗? (因为路径看起来没什么问题,如果路径不正常,它会死在Loader.php中,不是吗?)

  2. 一些类型的依赖会导致这个问题,在它导致一个更致命的之前?


  3. 类名可能与已经存在的东西冲突吗?以前我有一些相当神秘的类名,如MalaFwk_Application_Receiver。现在,名称更通用,例如CApplication,CComponent,CDatabase,CLogger等。


有效,但我愿意尝试任何人建议。如果这不是一个特别有建设性的问题,我提前道歉,但是我没有想法,还有太多(微不足道的,但是广泛的)的变化来恢复和重新应用这些变化。任何帮助将不胜感激。 (我会回到美国东部时间晚上8点45分。)

更新:

如果我将以下行添加到 index.php ,即在任何其他事情发生之前手动要求文件,那么事情就会重新开始。

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

因此,出于某种原因,在代码达到 send(),它找不到库。什么可能导致这种情况?

解决方案

请将此添加到您的索引:

  set_include_path(implode(PATH_SEPARATOR,array(
realpath('../ library'),//确认这是你的库文件夹的正确路径
get_include_path(),
)));


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?

解决方案

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(),
)));

这篇关于PHP,Zend,require_once:“无法打开流”和“无法打开所需的”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆