Re: [PHP] Question about includes

2009-11-24 Thread Al



Brady Mitchell wrote:

On Tue, Nov 24, 2009 at 6:22 AM, Al  wrote:

This bothers since the current working directory is effectively where my
original script resides; is it not? If so, doesn't the "include Net/SMTP.php
on line 206" look for the path relative to it and not in
/home1/youstart/php/?


When including a file with a relative path PHP starts at the beginning
of the include_path and checks each directory until it finds the file
or reaches the end of the list. In this case it will start with the
current directory since you've got the . as the first entry in the
include path.

When using relative paths, it's relative to the script with the
include statement. So if you have a script myscript.php that includes
mail.php, that include will be relative to myscript.php. Then when you
include smtp.php from mail.php, the relative path will be relative to
mail.php, not myscript.php.

It looks like you're using PEAR classes, but the pear directory isn't
in the include path. Try adding that path to your include_path by
editing your .htaccess or using ini_set().

HTH,

Brady


Thanks Brady.  That's a clear explanation and most helpful. The PHP manual could 
use a better description like your's.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Question about includes

2009-11-24 Thread Brady Mitchell
On Tue, Nov 24, 2009 at 6:22 AM, Al  wrote:
> This bothers since the current working directory is effectively where my
> original script resides; is it not? If so, doesn't the "include Net/SMTP.php
> on line 206" look for the path relative to it and not in
> /home1/youstart/php/?

When including a file with a relative path PHP starts at the beginning
of the include_path and checks each directory until it finds the file
or reaches the end of the list. In this case it will start with the
current directory since you've got the . as the first entry in the
include path.

When using relative paths, it's relative to the script with the
include statement. So if you have a script myscript.php that includes
mail.php, that include will be relative to myscript.php. Then when you
include smtp.php from mail.php, the relative path will be relative to
mail.php, not myscript.php.

It looks like you're using PEAR classes, but the pear directory isn't
in the include path. Try adding that path to your include_path by
editing your .htaccess or using ini_set().

HTH,

Brady

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Question about includes

2009-11-24 Thread Al
I'm having an include problem on a shared host and need the answer to the 
following to cover a key point.


I'm getting this error:
Warning: include_once() [function.include]: Failed opening 'Net/SMTP.php' for 
inclusion include_path='.:/usr/lib/php:/usr/local/lib/php:/home1/youstart/php/') 
in /home1/youstart/php/Mail/smtp.php on line 206


What's going on is that my script calls /php/mail.php which includes 
/Mail/smtp.php.  smtp.php has "include Net/SMTP.php" on line 206.


This bothers since the current working directory is effectively where my 
original script resides; is it not? If so, doesn't the "include Net/SMTP.php on 
line 206" look for the path relative to it and not in /home1/youstart/php/?


If my assumption is correct, is there a way around the problem? Remember, this 
is a shared host and changing stuff above the /public_html is a real problem.


My script runs fine on 3 other Linux/Appache/cpanel shared-host servers.

Al...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php