calling functions in include()s

They have: 45 posts

Joined: Oct 2001

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's picture

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().

Smiling Suzanne

nike_guy_man's picture

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

Laughing out loud

They have: 45 posts

Joined: Oct 2001

oh, it's just a fake one to illustrate the point.

They have: 45 posts

Joined: Oct 2001

so i presume only require works then?

Suzanne's picture

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's picture

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.