Question

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 prepend 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 recognize 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))

Was it helpful?

Solution

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

OTHER TIPS

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).

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top