473,573 Members | 2,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'undefined function' error if I use a fully-qualifed include

This is a weird problem, but perhaps someone else has seen it before
(I hope!)

If I use a fully qualified include call

include ( 'http://localhost/subtree/filename.php')

I get an 'undefined function' error when calling a routine that's
defined in that file.

(I know the file is being included and the parser is at least seeing
the definition because I put disclosure echos before and after the
definition, and the echos work.)

But the error goes away and the function executes if I use a relative
reference

include ('subtree/filename.php')

even though subtree is *not* declared in the include_path config var
in php.ini.

Thanks in advance for any ideas. I'm stumped!

-Puzzled in Rainy Massachusetts
Oct 18 '05 #1
6 1892
Puzzled said the following on 18/10/2005 17:54:
This is a weird problem, but perhaps someone else has seen it before
(I hope!)

If I use a fully qualified include call

include ( 'http://localhost/subtree/filename.php')

I get an 'undefined function' error when calling a routine that's
defined in that file.


AAARGH! This question comes up practically every week!

This is an absolute *HTTP* URL, not an absolute *filesystem* URL. So it
obtains filename.php by performing an HTTP request to the specified
server, which just happens to be "localhost" in this case.

And of course, a server set up to parse and execute PHP files will parse
and execute filename.php when it's requested, so all your include() call
sees is the output result of filename.php.

--
Oli
Oct 18 '05 #2
Oli Filth wrote:
Puzzled said the following on 18/10/2005 17:54:
This is a weird problem, but perhaps someone else has seen it before
(I hope!)

If I use a fully qualified include call

include ( 'http://localhost/subtree/filename.php')

I get an 'undefined function' error when calling a routine that's
defined in that file.


AAARGH! This question comes up practically every week!

This is an absolute *HTTP* URL, not an absolute *filesystem* URL. So it
obtains filename.php by performing an HTTP request to the specified
server, which just happens to be "localhost" in this case.

And of course, a server set up to parse and execute PHP files will parse
and execute filename.php when it's requested, so all your include() call
sees is the output result of filename.php.


Thanks much for your quick reply.

I think I must be missing something important still, because I don't
understand what you said. Check me on this, would you?

A URL is just another filesystem reference, but using a highly
generalized syntax that's independent of o/s and physical
location--like NFS, but more general. So any processing that would
be done or not done to a file would be independent of the type of
reference used to retrieve it.

When the php interpreter knows it's operating on an include file, it
should know enough not to start a new symbol table, but instead add
things like function definitions to the existing symbol table it
started building when it read up the outermost file.

But that doesn't appear to be what's happening. It looks to me as
though it's treating the .php extension as being more important than
the fact the file is being included, so instead of continuing the same
symbol table, it's building a special one for that file and then
discarding it.

Is that what's causing the problem, the fact that I'm using a .php
extension on the include file?

That would make a crazy sort of sense, since the php interpreter would
do its own filesystem fetches, but might hand any url reference, even
one for an include, off to Apache to satisfy. And somewhere in that
process, the fact that it's just an include file is getting pushed and
the file is being interpreted as though it were a completely new job.
Whereas if it had some .inc or .foo extension, Apache wouldn't try to
pass it through the interpreter, but would just hand it over.

still Puzzled, but struggling
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Oct 19 '05 #3
Puzzled wrote:
Oli Filth wrote:
Puzzled said the following on 18/10/2005 17:54:
If I use a fully qualified include call

include ( 'http://localhost/subtree/filename.php')

I get an 'undefined function' error when calling a routine that's
defined in that file.
This is an absolute *HTTP* URL, not an absolute *filesystem* URL. So it
obtains filename.php by performing an HTTP request to the specified
server, which just happens to be "localhost" in this case.

And of course, a server set up to parse and execute PHP files will parse
and execute filename.php when it's requested, so all your include() call
sees is the output result of filename.php.


I think I must be missing something important still, because I don't
understand what you said. Check me on this, would you?

A URL is just another filesystem reference, but using a highly
generalized syntax that's independent of o/s and physical
location--like NFS, but more general. So any processing that would
be done or not done to a file would be independent of the type of
reference used to retrieve it.


In this case, not really, because the URL is prefixed with "http://",
which specifies "Go and get this resource using the HTTP protocol".

The fact is that you're requesting "filename.p hp" via HTTP. PHP doesn't
know that you're expecting it to implicitly convert
"http://localhost/..." to a local filesystem reference, so it simply
sends out an HTTP request for that file, just as if you'd typed
"http://localhost/.../filename.php" into your browser.

The request just so happens to be to your own server, which serves this
request by processing filename.php spitting the output back as the HTTP
response. This HTTP response is then included into the original PHP
file.
When the php interpreter knows it's operating on an include file, it
should know enough not to start a new symbol table, but instead add
things like function definitions to the existing symbol table it
started building when it read up the outermost file.
This is impossible, because filename.php is processed in a completely
separate instance to the original PHP file, serving an entirely
separate HTTP request.
Is that what's causing the problem, the fact that I'm using a .php
extension on the include file?

That would make a crazy sort of sense, since the php interpreter would
do its own filesystem fetches, but might hand any url reference, even
one for an include, off to Apache to satisfy. And somewhere in that
process, the fact that it's just an include file is getting pushed and
the file is being interpreted as though it were a completely new job.
Whereas if it had some .inc or .foo extension, Apache wouldn't try to
pass it through the interpreter, but would just hand it over.


Yup, that's the explanation in a nutshell (except that the first PHP
instance doesn't request filename.php directly from Apache, it does it
via an HTTP request which lands at Apache indirectly).

The simplest solution would be to not include() local files via HTTP.

Even if you renamed your include files to .inc extensions, this would
be insecure, since anyone could request them via HTTP and view your
source code.

--
Oli

Oct 19 '05 #4

Puzzled wrote:
This is a weird problem, but perhaps someone else has seen it before
(I hope!)

If I use a fully qualified include call

include ( 'http://localhost/subtree/filename.php')

I get an 'undefined function' error when calling a routine that's
defined in that file.

(I know the file is being included and the parser is at least seeing
the definition because I put disclosure echos before and after the
definition, and the echos work.)

But the error goes away and the function executes if I use a relative
reference

include ('subtree/filename.php')

even though subtree is *not* declared in the include_path config var
in php.ini.


if the subtree folder is in the same folder as the current script, php
knows to look for that folder in the current folder. same as include
'filename.php', it looks in the current folder.

if you are looking to include a file relative to the main folder of
your site, try
include $_SERVER['DOCUMENT_ROOT'].'subtree/filename.php'
(you may need a slash before subtree)

--
juglesh

Oct 19 '05 #5
Oli Filth wrote:
Puzzled wrote:
Oli Filth wrote:
>Puzzled said the following on 18/10/2005 17:54:
>> If I use a fully qualified include call
>>
>> include ( 'http://localhost/subtree/filename.php')
>>
>> I get an 'undefined function' error when calling a routine that's
>> defined in that file.
>
>This is an absolute *HTTP* URL, not an absolute *filesystem* URL. So it
>obtains filename.php by performing an HTTP request to the specified
>server, which just happens to be "localhost" in this case.
>
>And of course, a server set up to parse and execute PHP files will parse
>and execute filename.php when it's requested, so all your include() call
>sees is the output result of filename.php.


I think I must be missing something important still, because I don't
understand what you said. Check me on this, would you?

A URL is just another filesystem reference, but using a highly
generalized syntax that's independent of o/s and physical
location--like NFS, but more general. So any processing that would
be done or not done to a file would be independent of the type of
reference used to retrieve it.


In this case, not really, because the URL is prefixed with "http://",
which specifies "Go and get this resource using the HTTP protocol".

The fact is that you're requesting "filename.p hp" via HTTP. PHP doesn't
know that you're expecting it to implicitly convert
"http://localhost/..." to a local filesystem reference, so it simply
sends out an HTTP request for that file, just as if you'd typed
"http://localhost/.../filename.php" into your browser.

The request just so happens to be to your own server, which serves this
request by processing filename.php spitting the output back as the HTTP
response. This HTTP response is then included into the original PHP
file.
When the php interpreter knows it's operating on an include file, it
should know enough not to start a new symbol table, but instead add
things like function definitions to the existing symbol table it
started building when it read up the outermost file.


This is impossible, because filename.php is processed in a completely
separate instance to the original PHP file, serving an entirely
separate HTTP request.
Is that what's causing the problem, the fact that I'm using a .php
extension on the include file?

That would make a crazy sort of sense, since the php interpreter would
do its own filesystem fetches, but might hand any url reference, even
one for an include, off to Apache to satisfy. And somewhere in that
process, the fact that it's just an include file is getting pushed and
the file is being interpreted as though it were a completely new job.
Whereas if it had some .inc or .foo extension, Apache wouldn't try to
pass it through the interpreter, but would just hand it over.


Yup, that's the explanation in a nutshell (except that the first PHP
instance doesn't request filename.php directly from Apache, it does it
via an HTTP request which lands at Apache indirectly).

The simplest solution would be to not include() local files via HTTP.

Even if you renamed your include files to .inc extensions, this would
be insecure, since anyone could request them via HTTP and view your
source code.


Again thanks for another prompt response (more prompt than mine, since
everyone's having phone problems around here due to rain)

So it sounds as though there's no really good, general solution.
Either I use an extension that doesn't trigger interpretation, and
suffer code-snooping, or I keep duplicate copies on each server and
load using relative refs. *sigh*

Many thanks for the deconfusion!

- less-Puzzled-now
Oct 21 '05 #6
Puzzled wrote:
Oli Filth wrote:

Puzzled wrote:
Oli Filth wrote:
Puzzled said the following on 18/10/2005 17:54:

>If I use a fully qualified include call
>
> include ( 'http://localhost/subtree/filename.php')
>
>I get an 'undefined function' error when calling a routine that's
>defined in that file.

This is an absolute *HTTP* URL, not an absolute *filesystem* URL. So it
obtains filename.php by performing an HTTP request to the specified
server, which just happens to be "localhost" in this case.

And of course, a server set up to parse and execute PHP files will parse
and execute filename.php when it's requested, so all your include() call
sees is the output result of filename.php.

I think I must be missing something important still, because I don't
understand what you said. Check me on this, would you?

A URL is just another filesystem reference, but using a highly
generalize d syntax that's independent of o/s and physical
location--like NFS, but more general. So any processing that would
be done or not done to a file would be independent of the type of
reference used to retrieve it.


In this case, not really, because the URL is prefixed with "http://",
which specifies "Go and get this resource using the HTTP protocol".

The fact is that you're requesting "filename.p hp" via HTTP. PHP doesn't
know that you're expecting it to implicitly convert
"http://localhost/..." to a local filesystem reference, so it simply
sends out an HTTP request for that file, just as if you'd typed
"http://localhost/.../filename.php" into your browser.

The request just so happens to be to your own server, which serves this
request by processing filename.php spitting the output back as the HTTP
response. This HTTP response is then included into the original PHP
file.

When the php interpreter knows it's operating on an include file, it
should know enough not to start a new symbol table, but instead add
things like function definitions to the existing symbol table it
started building when it read up the outermost file.


This is impossible, because filename.php is processed in a completely
separate instance to the original PHP file, serving an entirely
separate HTTP request.

Is that what's causing the problem, the fact that I'm using a .php
extension on the include file?

That would make a crazy sort of sense, since the php interpreter would
do its own filesystem fetches, but might hand any url reference, even
one for an include, off to Apache to satisfy. And somewhere in that
process, the fact that it's just an include file is getting pushed and
the file is being interpreted as though it were a completely new job.
Whereas if it had some .inc or .foo extension, Apache wouldn't try to
pass it through the interpreter, but would just hand it over.


Yup, that's the explanation in a nutshell (except that the first PHP
instance doesn't request filename.php directly from Apache, it does it
via an HTTP request which lands at Apache indirectly).

The simplest solution would be to not include() local files via HTTP.

Even if you renamed your include files to .inc extensions, this would
be insecure, since anyone could request them via HTTP and view your
source code.

Again thanks for another prompt response (more prompt than mine, since
everyone's having phone problems around here due to rain)

So it sounds as though there's no really good, general solution.
Either I use an extension that doesn't trigger interpretation, and
suffer code-snooping, or I keep duplicate copies on each server and
load using relative refs. *sigh*

Many thanks for the deconfusion!

- less-Puzzled-now


PMJI, but I think you're better having duplicate copies of your code on
each server.

For instance - what happens if the server holding the (single) copy of
your code goes down? It does happen! :-) None of the other servers would
be able to access the code - and all would effectively be down.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Oct 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8265
by: Dan Finn | last post by:
OpenBSD 3.2 Apache 1.3.26 PHP 4.3.4 PHP-Nuke 6.9 getting these in the apache error log: Sun Nov 16 20:20:16 2003] PHP Notice: Undefined variable: HTTP_USER_AGENT in /htdocs/nuke/html/mainfile.php on line 16 PHP Notice: import_request_variables(): No prefix specified - possible security hazard in
2
13111
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on Unixware/C++/AT&T componets environment. I have been able to compile all modules after making necessary changes in LINUX/gcc/STL environment. We have two...
5
2153
by: Reza Roby | last post by:
The following code reports a runtime error "v has no properties." function ff() { var v; v.x=5; //error alert(v.x); } But this one alerts "undefined":
6
2162
by: David N | last post by:
Hi All, What is a best way to handle an undefined value object class that returned from a function. I have a function that call the ADO.NET ExecuteScalar() function and returns the object to the calling function as follow: public object FunctionA() { object RetVal;
4
5721
by: r.nikhilk | last post by:
Hi, We are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by including the -q64 option in xlC compiler. But, when we link all these libraries to one of the main applications, we are getting the following errors: ld:...
49
14453
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On http://www.webreference.com/programming/javascript/gr/column9/ they say: <snip> The undefined property A relatively recent addition to JavaScript is the undefined property.
9
1487
by: Chad | last post by:
The input file is: Params 1 2 3 4 5 6,7 Data 1,1
45
4808
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4,...
3
11591
by: prakash.mirji | last post by:
Hello, I am getting below mention linker error when I tried to link my class test.C I use below command to compile test.C /usr/bin/g++ -g -fpic -fvisibility=default -D_POSIX_SOURCE -DTRACING - D__EXTENSIONS__ -D__RWCOMPILER_H__ -D_REENTRANT -D_RWCONFIG=8s - D_RWCONFIG_12d -D_RWSTDDEBUG -DRWDEBUG -o test1 test1.o -L/lib -
14
1424
by: jl_post | last post by:
Hi, I've heard that if you've declared a variable (such as a double or an int) and not initialize it, then the result of printing out its value is undefined. I've also heard that "undefined behavior" can mean just about anything, such as "flying monkeys shooting out of your nose." Sure, that's an exaggeration, but normally I interpret...
0
7699
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8027
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7788
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5594
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5292
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3733
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3733
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2216
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1041
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.