Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.2 Notice: Use of undefined constant __DIR__ - assumed '__DIR__ [closed]

Tags:

php

In php 5.3 or less it'll provide an error like the following:

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??

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);
like image 935
chrisjlee Avatar asked Feb 01 '13 19:02

chrisjlee


1 Answers

Use the old trick:

dirname(__FILE__)

But if possible, update to a newer version of PHP.

like image 175
Tchoupi Avatar answered Nov 15 '22 16:11

Tchoupi