Re: Making functions available from another script

From: Date: Mon, 07 Nov 2005 09:12:35 +0000
Subject: Re: Making functions available from another script
References: 1  Groups: php.general php.general 
Request: Send a blank email to php-general+get-225229@lists.php.net to get a copy of this message
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?

« previous php.general (#225229) next »