15

PHP 5.3 以下では、次のようなエラーが表示されます。

Notice: Use of undefined constant __DIR__ - assumed '__DIR__

魔法の定数を使っているからです__DIR____DIR__5.3以下で使用する代替手段はありますか??

原因となっているコードは次のとおりです。

<?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);
4

1 に答える 1

47

古いトリックを使用します。

dirname(__FILE__)

ただし、可能であれば、新しいバージョンの PHP に更新してください。

于 2013-02-01T19:53:26.897 に答える