PHP 5 function redeclared error

This is a discussion on PHP 5 function redeclared error within the PHP Language forums, part of the PHP Programming Forums category; .oO(sesser@gmail.com) >>There is nothing wrong with PHP w.r.t require_once. The problem is, in &...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 01-12-2005
Michael Fesser
 
Posts: n/a
Default Re: PHP 5 function redeclared error

.oO(sesser@gmail.com)

>>There is nothing wrong with PHP w.r.t require_once. The problem is, in

>machine 2:
>>.../home -> has a functions.php
>>.../home/secure/ -> also has a functions.php

>
>this proves that the require_once('functions.php') in contents.php is
>failing on server 1...


No!

>there is no functions.php in the 'home'
>directory (which is where PHP is looking for the file).


PHP looks there first, if it can't find one it looks in /home/secure
(the same directory where contents.php is stored). It's all correct.

Micha
Reply With Quote
  #12 (permalink)  
Old 01-12-2005
sesser@gmail.com
 
Posts: n/a
Default Re: PHP 5 function redeclared error

My bad. I was unaware that it would look in the 'secure' directory if
it failed in the 'home' directory. Not to mention that 'require()'
would produce a fatal error if it couldn't find a file.

thanks
r.

Reply With Quote
  #13 (permalink)  
Old 01-12-2005
chernyshevsky@hotmail.com
 
Posts: n/a
Default Re: PHP 5 function redeclared error

I was trying to simplify things a bit. Unless you change it with a call
to chdir(), the cwd is the same as the script directory. Including a
file in a different directory does not change the cwd to that
directory.

I'm at a loss as to why require_once("functions.php") manages to find
secure/functions.php. I think most of us would agree that it's not
supposed to happen, unless /home/secure is in the include_path. If it
is, then why does require_once() fail to see that it's the same file?
Since this happens on Windows, maybe it's a forward slash vs. backward
slash misinterpretation within PHP.

In any event, providing absolute paths to include/require is the
preferred practice. That way you know for certain what you're
including. An example:

define('SECURE_INCLUDE_ROOT', dirname(__FILE__) . "/secure/");

function require_secure($filename) {
require_once(SECURE_INCLUDE_ROOT . $filename);
}

Reply With Quote
  #14 (permalink)  
Old 01-12-2005
Andy Hassall
 
Posts: n/a
Default Re: PHP 5 function redeclared error

On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@hotmail.com"
<chernyshevsky@hotmail.com> wrote:

>I was trying to simplify things a bit. Unless you change it with a call
>to chdir(), the cwd is the same as the script directory. Including a
>file in a different directory does not change the cwd to that
>directory.


Yes, that's the point from the manual snippet I posted. cwd is searched first,
then the directory containing the current script. When you include a script
outside the cwd, then all include_path directories relative the directory
containing the included script become candidates for searching, once all
equivalents relative to cwd fail.

--
Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Reply With Quote
  #15 (permalink)  
Old 01-13-2005
Chung Leong
 
Posts: n/a
Default Re: PHP 5 function redeclared error

"Andy Hassall" <andy@andyh.co.uk> wrote in message
news:fa5bu018v6rn9v08iiiolm8n7mmugraig5@4ax.com...
> On 12 Jan 2005 12:59:47 -0800, "chernyshevsky@hotmail.com"
> <chernyshevsky@hotmail.com> wrote:
>
> >I was trying to simplify things a bit. Unless you change it with a call
> >to chdir(), the cwd is the same as the script directory. Including a
> >file in a different directory does not change the cwd to that
> >directory.

>
> Yes, that's the point from the manual snippet I posted. cwd is searched

first,
> then the directory containing the current script. When you include a

script
> outside the cwd, then all include_path directories relative the directory
> containing the included script become candidates for searching, once all
> equivalents relative to cwd fail.
>
> --
> Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk>
> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool


Crap. I got egg on my face. I've always understood "current script" as being
the file reported by PHP_SELF. Turned out I'm way off. Thank you, Andy and
Michael, for point it out.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:43 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0