|
Posted by "Arno Kuhl" on 11/07/05 11:57
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@richitek.net]
Sent: 07 November 2005 11:33
To: 'Norbert Wenzel'
Cc: php-general@lists.php.net
Subject: RE: [PHP] 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@brain4art.at]
> Sent: Monday, 7 November 2005 5:13 pm
> To: php-general@lists.php.net; Richard Leclair
> Cc: php-general@lists.php.net
> Subject: [PHP] 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
Navigation:
[Reply to this message]
|