PHP 5.2 Примечание: использование undefined constant __DIR__ - предполагается '__DIR__ - программирование

PHP 5.2 Примечание: использование undefined constant __DIR__ - предполагается '__DIR__

В 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);
4b9b3361

Ответ 1

Используйте старый трюк:

dirname(__FILE__)

Но если возможно, обновите новую версию PHP.