PHP 5.2 注意:使用未定义的常量 __DIR__ - 假定为 '__DIR__
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14653947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP 5.2 Notice: Use of undefined constant __DIR__ - assumed '__DIR__
提问by chrisjlee
In php 5.3 or less it'll provide an error like the following:
在 php 5.3 或更低版本中,它会提供如下错误:
Notice: Use of undefined constant __DIR__ - assumed '__DIR__
It's because i'm using the magic constant __DIR__. Is there an alternative to using __DIR__in 5.3 or less??
这是因为我正在使用魔法常量__DIR__。有没有__DIR__在 5.3 或更低版本中使用的替代方法?
Here's the code that's causing it:
这是导致它的代码:
<?php
/**
* Load template files
*
* $files Contains alphabetized list of files that will be required
*/
$files = array(
'elements.inc',
'form.inc',
'menu.inc',
'theme.inc',
);
function _zurb_foundation_load($files) {
$tp = drupal_get_path('theme', 'zurb_foundation');
$file = '';
// Workaround for magic constant; for now because of php 5.2 issue
// http://drupal.org/node/1899620#comment-6988766
if( !defined( __DIR__ ) )define( __DIR__, dirname(__FILE__) );
// Check file path and '.inc' extension
foreach($files as $file) {
$file_path = __DIR__ .'/inc/' . $file;
if ( strpos($file,'.inc') > 0 && file_exists($file_path)) {
require_once($file_path);
}
}
}
_zurb_foundation_load($files);
回答by Tchoupi
Use the old trick:
使用旧技巧:
dirname(__FILE__)
But if possible, update to a newer version of PHP.
但如果可能,请更新到较新版本的 PHP。

