简体   繁体   English

是什么会导致include语句上的PHP错误?

[英]What could cause a PHP error on an include statement?

Ok, this was a stupid mistake. 好的,这是一个愚蠢的错误。 Had nothing to do with permissions or anything else I thought it might be. 与权限无关,或者与我认为可能无关的任何其他内容。 It was a simple syntax error in a file I didn't even think was being loaded. 这是我什至不认为正在加载的文件中的一个简单语法错误。

Reminds me of a quote from the first computer science teacher I ever had: 让我想起了我有过的第一位计算机科学老师的一句话:

"If you are certain that all of your code is correct, and the program doesn't work, something you are certain of is wrong." “如果您确定所有代码都是正确的,并且该程序无法运行,那么您肯定会出错。”

Sorry for the goose chase. 抱歉追赶鹅。

Original Post: 原始帖子:

I've got a bug in my PHP code that's been terrorizing me for several days now. 我的PHP代码中有一个bug困扰着我好几天了。

I'm trying to clasp in a new module to an existing Magento (v1.4) site, though I'm very new to the Magento framework. 尽管我对Magento框架很陌生,但我正在尝试将其添加到现有Magento(v1.4)网站的新模块中。 I think I am pretty close to getting to "Hello, World" on a block that I want displayed in the backend, but I'm getting a 500 error when the menu item is selected. 我想我非常接近要在后端显示的块上的“ Hello,World”,但是选择菜单项时出现500错误。

I managed to track it down (using echo stmts) to a line in the Layout.php file (app\\code\\core\\Mage\\Core\\Model\\Layout.php, line 472ish): 我设法(使用echo stmts)将其跟踪到Layout.php文件中的一行(app \\ code \\ core \\ Mage \\ Core \\ Model \\ Layout.php,第472ish行):

        if (class_exists($block, false) || mageFindClassFile($block)) {
            $temp = $block;
            echo "<p>before constructor: $temp</p>";
            $block = new $block($attributes);
            echo "<p>after constructor: $temp</p>";
        }

For my block, this yields only "before constructor...", so I know this is what is failing. 对于我的块,这仅产生“ before constructor ...”,因此我知道这是失败的。 A little more debugging reveals that the class in $block (the new block I am trying to show) does not exist. 进一步的调试显示,$ block(我要显示的新块)中的类不存在。 I would have expected the __autoload function to take care of this, but none of my echos in __autoload are displaying. 我本来希望__autoload函数可以解决此问题,但是__autoload中的所有回显都没有显示。

As a last ditch effort, I tried an include statement in Mage.php to the absolute location of the block class, but similar before and after echos reveal that that include statement becomes the breaking line. 作为最后的努力,我在Mage.php中尝试了一个include语句到块类的绝对位置,但是在回显前后发现该include语句成为了折线,这与之前类似。

I'm tempted to start thinking "permissions", but I'm not well versed in the server management side of all this, and I have limited access to the test server (the test server belongs to the client). 我很想开始考虑“权限”,但是我不熟悉服务器管理方面的所有方面,而且我对测试服务器的访问权限有限(测试服务器属于客户端)。

To anticipate the question: there are no errors reported in the PHP log file. 预料到该问题:PHP日志文件中未报告任何错误。 I am actually not convinced that this site is reporting errors to the log file (I haven't seen anything from this site), though the client is certain that everything is turned on. 我实际上并不确信该站点正在向日志文件报告错误(我从该站点没有看到任何东西),尽管客户端可以确定一切都已打开。

IIS 7. Integrated mode, I'm pretty sure. IIS 7.集成模式,我很确定。 Anyone know what could be causing this? 有人知道是什么原因造成的吗?

Per Joe's questions: Per Joe的问题:

The name of the block is FiveTalent_BikeCompat_Adminhtml_Block_Bikes . 块的名称是FiveTalent_BikeCompat_Adminhtml_Block_Bikes
The class is in the file [magento_root]\\app\\code\\local\\FiveTalent\\BikeCompat\\Adminhtml\\Block\\Bikes.php . 该类位于文件[magento_root] \\ app \\ code \\ local \\ FiveTalent \\ BikeCompat \\ Adminhtml \\ Block \\ Bikes.php中 The mageFindClassFile function confirms that it finds the file for the class. mageFindClassFile函数确认已找到该类的文件。

I'm pretty sure I am using Magento's loading methods properly. 我很确定我正在正确使用Magento的加载方法。 Admittedly the path pattern is a little different from your example, but I think this is because I am trying to create an Adminhtml block. 诚然,路径模式与您的示例有些不同,但是我认为这是因为我正在尝试创建Adminhtml块。 This is the action on the controller that is executing: 这是对正在执行的控制器的操作:

public function indexAction() {
    $this->loadLayout();
    $block = $this->getLayout()->createBlock('adminhtml/bikes', 'bikecompat');
    $this->_addContent($block);
    $this->renderLayout();
}

Again, I'm back to the question of the webserver (IIS, in this case) having rights to read the file. 再次,我回到Web服务器(在本例中为IIS)拥有读取文件权限的问题。 I'll see if I can't get hold of someone with access to the server to check this. 我将查看是否无法找到有权访问该服务器的人员来进行检查。

error_log php configuration directive can be used to set custom error log php配置指令error_log可用于设置自定义错误日志
and log_errors one will direct all error messages there. log_errors将所有错误消息定向到那里。

Errors in __autoload will NOT be displayed, evar. __autoload中的错误将不会显示,evar。 Youre on your own in __autoload. 您自己使用__autoload。 I'd seriously test my __autoload function. 我会认真测试我的__autoload函数。 I'd check for capitalization errors, it might be an issue. 我要检查大写错误,这可能是一个问题。

The Magento autoloader works just fine. Magento自动装带器工作正常。 Please echo the value of $block and add that to your question. 请回显$ block的值,并将其添加到您的问题中。 Your block name will probably follow the naming convention: YourCompany_YourModule_Block_Some_Path . 您的块名称可能会遵循以下命名约定: YourCompany_YourModule_Block_Some_Path If that not the case, that is probably your error. 如果不是这种情况,那可能是您的错误。 If that is the case, please make sure that the file (obviously, switch path to match your class) app/code/local/YourCompany/YourModule/Block/Some/Path.php exists and contains the right class declaration. 在这种情况下,请确保文件(显然,切换路径以匹配您的类) app/code/local/YourCompany/YourModule/Block/Some/Path.php存在并且包含正确的类声明。 If that is also true, make sure that Apache has the rights to read that file. 如果也是如此,请确保Apache有权读取该文件。

Once you've figured out this issue, you may want to consider moving over to Magento's loading methods. 解决此问题后,您可能需要考虑转移到Magento的加载方法。 The "right" way to do this in Magento (assuming the above classname again) is: 在Magento中做到这一点的“正确”方法(再次假设上面的类名)是:

<?php
Mage::getLayout()->createBlock("yourmodule/some_path");

Using the Magento loader will save you a lot of trouble later down the road, and allow others to use your Magento code with more assurance. 使用Magento加载程序将为您免除日后的麻烦,并使其他人可以更有把握地使用您的Magento代码。

Hope that helps! 希望有帮助!

Thanks, Joe 谢谢乔

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM