Reputation: 17530
I've built a PHP project in Windows, and as you know in Windows fun.php and Fun.php is same but not in Linux.
Q1-> As my project will run in Linux How to solve this issue [error for file name] ?
Q2-> I need to show an error if exact file name does not exist ! How to do so ?
Example
I have this 2 PHP file in template.php
and render.php
Code of render.php
include 'Template.php';
I want to get an warning so i can fix this issue [which does not create problem in Windows, but in Linux]
Upvotes: 3
Views: 13535
Reputation: 82038
Well, if I were in that situation, I'd write a wrapper around include:
function warned_include($file)
{
if( defined( 'DEBUG_ENV' ) ) // define this somewhere else while in dev.
{
foreach( explode( PATH_SEPARATOR, get_include_path() ) as $path )
{
// make sure the / is replaced with the OS native DIRECTORY_SEPARATOR
$fullPath = str_replace($path .DIRECTORY_SEPARATOR.$file, '/', DIRECTORY_SEPARATOR);
if( is_file( $fullPath ) )
{
$spl = new SplFileInfo( $fullPath );
if( $spl->getPathname() != $fullPath )
{
echo 'case sensitivity mismatch for ' . $spl->getPathname();
}
break;
}
}
}
include $file;
}
I've not had a chance to test it, but SplFileInfo gets the pathname from the OS, which means that it should have correct case sensitivity in Windows.
Upvotes: 5
Reputation: 360
Solution #1: Use all lowercase. Solution #2: Use the exact same case every time. Instead of trying to include "Template" when the file name is "template", just include the lowercase "template" in the first place. Most programming languages are case sensitive anyway, so it's best to get into the practice. While filename may be unique in this matter, for example, a variable in PHP must use the same case, so just apply the same principals to file names.
Upvotes: 4
Reputation: 10492
May be you should replace all includes with require. Require throws fatal error if there is no such file exists (not in proper case too)
YOu might find this helpful. - http://clarityamidstchaos.wordpress.com/2008/10/24/how-to-perform-a-case-insensitive-file_exists-lookup-in-phplinux/
Upvotes: 1
Reputation: 64409
You have a 'shortcut' in windows where you call a file Template
while it is actually calles template
. If you just go trough your code and not allow that, you'd be fine?
If for some reason you don't want that, you can always use an autoloader for classes. Every class that is called will load that class if it can't find itself. this will obviously be not ideal for situations where you want to include stuff that is not in classes.
Upvotes: 1