Error with __DIR__ using Moodle 2.3 + php 5.3 or 5.4

Error with __DIR__ using Moodle 2.3 + php 5.3 or 5.4

av Louis Barthou -
Antall svar: 3

Moodle version : Moodle 2.3.1+ (Build: 20120831)
PHP version : tested with 5.3.16 and 5.4.6.  (with the same issue).
Website hosted by OVH.

Our Moodle web site is correctly working, except in one specific situation.

When trying to download a zip file from a course, we get the following display :

Notice: Use of undefined constant __DIR__ - assumed '__DIR__' in /home/username/www/moodle/lib/dml/moodle_database.php on line 27

Warning: require_once(__DIR__/database_column_info.php) [function.require-once]: failed to open stream: No such file or directory in /home/username/www/moodle/lib/dml/moodle_database.php on line 27

Fatal error: require_once() [function.require]: Failed opening required '__DIR__/database_column_info.php' (include_path='/home/username/www/moodle/lib/zend:/home/username/www/moodle/lib/pear:.:/usr/local/lib/php') in /home/username/www/moodle/lib/dml/moodle_database.php on line 27

Everything is fine for other kinds of files (pdf and many others).
If we change the .zip extension to something else, as .abc, then it is possible to download the file...

Would you have an idea about how to fix this ? Thanks !

Additional info : with OVH (hosting our web site), the PHP version is selected in the .access file located at the root of the moodle folder.

Using PHP 5.3 or 5.4, the constant "__DIR__" should be defined as this is explained in : http://php.net/manual/en/language.constants.predefined.php

However, the displayed error mgs says that this constant is undefined. I don't understand how this may happen, and why this only happens when trying to download a zip file.

Gjennomsnittlig vurdering: -
Som svar til Louis Barthou

Re: Error with __DIR__ using Moodle 2.3 + php 5.3 or 5.4

av Petr Skoda -
Bilde av Core developers Bilde av Documentation writers Bilde av Peer reviewers Bilde av Plugin developers
Hello, your site is still using PHP 5.2.x, you need to find out how to switch it to later version. Please contact your server administrator if you need more help.
Som svar til Petr Skoda

Re: Error with __DIR__ using Moodle 2.3 + php 5.3 or 5.4

av Louis Barthou -

Thanks Petr, the strange point is that phpinfo (that we may call from Moodle) does display that we are using the release 5.3.16 or the release 5.4.6 according to the setting done in .htaccess, and everything else is fine (with php 5.2, we would already be in trouble during installation, according to some others posts).

On the other hand, I know that if it is needed to launch a script (as for instance the admin/cli/cron.php) directly from the server (not from a remote computer calling our web site using an internet browser as Firefox, but for example as a cron task or from a putty window) then there are some configuration problems.

The point is that we are using a "shared hosting service", not a dedicated server. We do have a possibility to choose the php version and to set up some settings thru the use of a .htaccess file located at the root of the moodle folder, and this will work if a php page is remotely used from another computer (using an internet browser), but we can't control the settings that will be used when a php script is directly used from the server, as for instance within a cron task, or using a direct command line (thru putty).
But I don't know if this may explain the error that we get here.

(it could if a moodle script was calling another moodle script thru a specific kind of system call (?), possibly using another instance of php or others settings of php but this seems quite strange...)

I don't know if the fact that the "magic constant" __DIR__ is not defined inside www/moodle/lib/dml/moodle_database.php may help to understand what is happening... Thanks again for your help !

Som svar til Louis Barthou

Re: Error with __DIR__ using Moodle 2.3 + php 5.3 or 5.4

av syl pub -

Hello

I'm facing the same issue with  Moodle 2.3.2+ (Build: 20120920) on an ovh server (pro account).

I can't cope with zip, mp3 and wav files. Did you find a solution?