calling functions in include()s
suppose i have this:
fncs.php:
<?php
function countposts ($blah) {
$blah = $blah + 1;
return $blah;
}
?>
and then i have another file:
<?php
include(fncs.php);
echo countposts(2);
?>
For some reason, it says calling undefined function... So what's wrong here? Thanks for any help!
Suzanne posted this at 17:41 — 6th January 2002.
She has: 5,507 posts
Joined: Feb 2000
you should probably use require instead of include. And have quotes around the filename.
But I'm just a beginner, so check out php.net for more information on include() and require().
Suzanne
nike_guy_man posted this at 19:10 — 6th January 2002.
They have: 840 posts
Joined: Sep 2000
Thats just what I was thinking.
I use require() a lot on my site, and I pass functions between them, and they all work
Make it
<?php
require('fncs.php');
echo countposts(2);
?>
Just out of curiousity, what does this script do?
Thanks
aqzsvwx12345 posted this at 20:29 — 7th January 2002.
They have: 45 posts
Joined: Oct 2001
oh, it's just a fake one to illustrate the point.
aqzsvwx12345 posted this at 20:33 — 7th January 2002.
They have: 45 posts
Joined: Oct 2001
so i presume only require works then?
Suzanne posted this at 20:45 — 7th January 2002.
She has: 5,507 posts
Joined: Feb 2000
did you use quotes around the name?
did you try require?
did you read the information at php.net?
Without seeing what you are actually doing, it's impossible to do more than just point you in the right direction.
Suzanne
Mark Hensler posted this at 01:00 — 8th January 2002.
He has: 4,048 posts
Joined: Aug 2000
Include should work.
My guess is that PHP choked without quotes.
Also note worthy. Require() does just that. It requires that the file be included. If it fails for one reason or another, the whole script will die (with an error printed). Include() does not require that the file be included. If the include fails an error will be printed, but the rest of the script will be executed.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.