RE: Re: Making functions available from another script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



DOH!!  Okay, I've sorted out the [my] problem...

Instead of just doing the include relatively, I tried including it via the
full URL, ie. <?php include("http://$_SERVER[HTTP_HOST]/lib.php";); ?>

I guess it just includes output of the result of this typical HTTP parse.
By just doing <?php include("./lib.php"); ?>, everything works fine.
(Providing of course that the two files exist in the same directory.)

-------------------------------------------------------
If you're interested, this is what I used to test it with:

lib.php:
--------
<?php
function doit($s)   { return "done: $s\n"; }
function listem($s) { print "1 $s, 2 ". $s. "s, lots of ".$s."s.\n"; }
?>

A.php:
------
<?php include "http://$_SERVER[HTTP_HOST]/lib.php"; ?>
<HTML>
<BODY>
<H1>Something basic</H1>

<H2>Let's do stuff:</H2>
<?php
$todo = doit("put out the garbage.");
$todo .= doit("pay the mower guy.");
$todo .= doit("finish that letter.");
$todo .= doit("take a break.");
print "<PRE>\n$todo</PRE>\n";
?>

</BODY>
</HTML>
-------------------------------------------------------

Original included produced an undefined call to function doit().

Regards,
Richie !


> -----Original Message-----
> From: Arno Kuhl [mailto:akuhl@xxxxxxxxxxxx]
> Sent: Monday, 7 November 2005 5:58 pm
> To: php-general@xxxxxxxxxxxxx
> Subject: RE:  Re: Making functions available from another script
> 
> If it was working properly the function would be callable. Your include is
> probably not working - change it to "require" and see if you get an error.
> Using "include" doesn't give you an error if the include file is not
> found.
> 
> Arno
>  ________________________
>  DotContent
>  Professional Content Management Solutions
>  www.dotcontent.net
> 
> 
> -----Original Message-----
> From: Richard Leclair [mailto:richard@xxxxxxxxxxxx]
> Sent: 07 November 2005 11:33
> To: 'Norbert Wenzel'
> Cc: php-general@xxxxxxxxxxxxx
> Subject: RE:  Re: Making functions available from another script
> 
> 
> Hi Norbert,
> 
> Thanks for your reply.  Yeah, you were almost there - it wasn't quite what
> I
> had in mind.  I probably should have elaborated on this one.
> 
> I'm looking at building up a library of handy functions that can be
> included
> in a current script.
> 
> Only problem is:
> (let's just say for clarity that lib.php <==> A.php; same)..
> 
> If I declare the functions in lib.php, then B.php can include lib.php but
> cannot execute any functions within B.php (that were declared in lib.php).
> it keeps coming up as "function undeclared".
> 
> Any more ideas/thoughts?  Or have I not gone about this correctly?
> 
> Regards,
> Richie !
> 
> 
> > -----Original Message-----
> > From: Norbert Wenzel [mailto:mail@xxxxxxxxxxxx]
> > Sent: Monday, 7 November 2005 5:13 pm
> > To: php-general@xxxxxxxxxxxxx; Richard Leclair
> > Cc: php-general@xxxxxxxxxxxxx
> > Subject:  Re: Making functions available from another script
> >
> > Richard Leclair wrote:
> > > Hi PHP-ers,
> > >
> > > Here's an easy one:
> > > Q: How can I make a function available from within another php script?
> > >
> > > Eg. B.php contains:
> > >
> > > <?php include ".../fns.php" ?>
> > >
> > > Which has a function fn($x);
> > >
> > > Later on, I want to include this function in B.php somewhere.
> > >
> > > In short:  B.php wants to use fn($x) found in A.php.
> > >
> > > Regards,
> > > Richie !
> >
> > I'm not quite sure if I did get your question right, but you answered
> > the question yourself.
> >
> > include("anyfile.php"); does nothing more then "copy" the code of
> > anyfile.php to the file, in which it is called. anyfile.php is
> > interpreted as HTML, so you should have your <?php brackets around the
> > document.
> >
> > A.php-----------
> > function foo($bar) {
> > 	//do sth
> > }
> >
> > B.php-----------
> > include[_once]("A.php");
> >
> > $x = "anything you like";
> > $whatever = foo($x);
> >
> >
> > this works if A and B are in exactly the same directory, otherwise you
> > should change the path for the include call.
> >
> > Did I get your question right?
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux