PDA

View Full Version : Subs in PHP



Niaad
March 22nd, 2001, 16:02
I know a little bit of CGI, and one of the things that I do know is to make a sub, you do this:



sub TheSub {

print "This is a sub!";

}


And then to call it...



&TheSub


Well, recently I have been working a lot more with PHP, because I find it a lot easier. Anyway, I tried using code like that in PHP (considering a lot of CGI code is exactly the same in PHP), but I kept getting parse errors on the line "sub TheSub {". I went searching for any PHP tutorials that had information regarding this, but I couldn't find anything.

I am just curious, is there a different way of doing it in PHP? Or is it just not possible at all?

Gonzo
March 22nd, 2001, 17:14
use a function.

like this


function funname() {
echo "this is a function";
}

and call it like this
[/code]
funname();
[/code]

Niaad
March 23rd, 2001, 15:19
Ah! Thanks!

I am glad to see that using subs from other files, as long as the files are "required" at the beginning of the script, works fine.

Thanks again! :D