views:

286

answers:

4

We have an issue using the PEAR libraries on Windows from PHP.

Pear contains many classes, we are making use of a fair few, one of which is the Mail class found in Mail.php. We use PEAR on the path, rather than providing the full explicit path to individual PEAR files:

require_once('Mail.php');

Rather than:

require_once('/path/to/pear/Mail.php');

This causes issues in the administration module of the site, where there is a mail.php file (used to send mails to users). If we are in an administrative screen that sends an email (such as the user administration screen that can generate and email new random passwords to users when they are approved from the moderation queue) and we attempt to include Mail.php we "accidentally" include mail.php.

Without changing to pre-pend the full path to the PEAR install explicitly requiring the PEAR modules (non-standard, typically you install PEAR to your path...) is there a way to enforce PHP on Windows to require files case-sensitively?

We are adding the PEAR path to the include path ourselves, so have control over the path order. We also recognise that we should avoid using filenames that clash with PEAR names regardless of case, and in the future will do so. This page however (which is not an include file, but a controller), has been in the repository for some years, and plugins specifically generate URLS to provide links/redirects to this page in their processing.

(We support Apache, Microsoft IIS, LightHTTPD and Zeus, using PHP 4.3 or later (including PHP5))

+3  A: 

As it's an OS level thing, I don't believe there's an easy way of doing this.

You could try changing your include from include('Mail.php'); to include('./Mail.php');, but I'm not certain if that'll work on a Windows box (not having one with PHP to test on).

ceejayoz
Confirmed. It is an OS thing. Windows just isn't case sensitive when it comes to filenames so this isn't possible.
Splash
This is true, and would work, we do include our own include files with full paths, however, our mail.php is a controller. See http://stackoverflow.com/questions/63599/including-files-case-sensitively-on-windows-from-php#65937
THEMike
A: 

If you are using PHP 4, you can take advantage of this bug. Off course that is a messy solution...

Or you could just rename your mail.php file to something else...

Jan Hancic
+1  A: 

having 2 files with the same name in the include path is not a good idea, rename your files so the files that you wrote have different names from third party libraries. anyway for your current situation I think by changing the order of paths in your include path, you can fix this. PHP searches for the files in the include paths, one by one. when the required file is found in the include path, PHP will stop searching for the file. so in the administration section of your application, if you want to include the PEAR Mail file, instead of the mail.php that you wrote, change your include path so the PEAR path is before the current directory. do something like this:

<?php
  $path_to_pear = '/usr/share/php/pear';
  set_include_path( $path_to_pear . PATH_SEPARATOR . get_include_path() );
?>
farzad
I do not have enough reputation to edit, but, in essence this is an ideal answer:1) Don't get into the problem we have (make unique names)2) Work round it by tweaking the include order to use PEAR first as our files are NOT includes but controllers.
THEMike
A: 

I'm fairly certain this problem is caused by the NTFS code in the Win32 subsystem. If you use an Ext2 Installable File System (IFS), you should get case sensitivity on that drive.

MSalters