Forum Moderators: coopster
Functions like form validation, getting stuff into and out of a DB table, etc.
Each of these functions (which reside in a seperate .php file) start are like this:
<?php
function something() {
do some stuff...
}
?>
Now, here's the thing: I'm including these functions inside another <?php ...?> block (usually some conditional statement).
Since that's the case, I guess that when the script runs, this is what is going on:
<?php
some conditional statement {
<?php
function something () {
do some stuff...
}
?>
}
?>
Have I lost everyone with this example? Do you see what I mean?
What I've been doing works fine, but is it the right way to write external/included functions?
I guess I could have made this entire question a lot shorter by asking: If you create a generic function that is meant for "inclusion", do you start and end that function with <?php ...?>, or do you just start it with function something ()?
Neophyte
<?php
include('includes.php');
?>
Then my includes.php file looks like this:
<?php
include('file1.php');
include('file2.php');
etc...
?>
Each included file looks like this:
<?php
//Function: Do something
function something() {
//function script
}
//Function: Another function
function somethingelse() {
//function script
}
?>
This is just the way I do it, find it works out great. Good luck! Some people use classes, but I don't see the point in small PHP scripts. I find it's much easier to just be able to use something() in my scripts after include('includes.php').
I don't know if there's a better way.
Cheers.