Page 1 of 1

Weird error with specific file name

PostPosted: 28. March 2013 08:16
by danghm
I'm currently using XAMPP lite 1.7
Below is my test project

db.php
Code: Select all
<?php
function greeting() {
    echo "Ciao";
}

inc.php
Code: Select all
<?php
require 'db.php';

index.php
Code: Select all
<?php
require 'inc.php';

admin/index.php
Code: Select all
<?php
require '../inc.php';


Everything seems fine. The code run well on http://localhost/test/index.php, the greeting is echoed.
But when browsing to http://localhost/test/admin/index.php, XAMPP returns a fatal error:

Fatal error: Call to undefined function greeting() in D:\xampp\htdocs\test\admin\index.php on line 5


This error not orcur when I rename db.php to functions.php

How to fix that?

Re: Weird error with specific file name

PostPosted: 28. March 2013 09:58
by Altrea
Hi danghm,

Please start new threads with the words "Hi" or "Hello". A short salutation is an act of politeness. Even if the internet is an virtual area, there is always a human being behind the screen. A polite beginning is the first positive impression you can leave here and helps to get polite answers too. Please keep that in mind if you start a new thread in any community board. Thank you.

danghm wrote:
Fatal error: Call to undefined function greeting() in D:\xampp\htdocs\test\admin\index.php on line 5


This error not orcur when I rename db.php to functions.php

How to fix that?

This occurs because PEAR also has a db.php file which will get loaded with your require function instead of yours.
If you don't use PEAR you can easily remove the PEAR path from the include_path setting in your php.ini file.

best wishes,
Altrea

Re: Weird error with specific file name

PostPosted: 28. March 2013 15:31
by danghm
Hi Altrea,

Thanks for the answer and please excuse my bad behave. English is not my main language and I am very bad at it. I will keep your advice in mind. Again, thank you very much for your support.

Re: Weird error with specific file name

PostPosted: 28. March 2013 16:21
by Altrea
You're welcome :)