本文介绍了PHP 5.2注意:使用未定义的常量__DIR__-假定为'__DIR__的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在php 5.3或更低版本中,它将提供如下错误:
In php 5.3 or less it'll provide an error like the following:
Notice: Use of undefined constant __DIR__ - assumed '__DIR__
这是因为我正在使用魔法常数__DIR__
.在5.3以下的版本中可以使用__DIR__
替代吗?
It's because i'm using the magic constant __DIR__
. Is there an alternative to using __DIR__
in 5.3 or less??
这是引起它的代码:
<?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);
推荐答案
使用旧技巧:
dirname(__FILE__)
但是,如果可能,请更新到更高版本的PHP.
But if possible, update to a newer version of PHP.
这篇关于PHP 5.2注意:使用未定义的常量__DIR__-假定为'__DIR__的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!