Re: Problem with functions

From: Date: Fri, 20 Dec 2002 19:27:04 +0000
Subject: Re: Problem with functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-129012@lists.php.net to get a copy of this message
Jon, You may have answered my question, but I'm still confused. I see from your example that the actual function comes before the function is called in the script, and when I changed mine to that format it worked. Now the confusion. I have another script which is the opposite of your example, and works fine. So why would one work one way but not the other. I have included the exact format I have for the one that doesn't work, and below that the actual code of the one that does work. In most languages I have used, this is the correct format - it makes for easier reading. <?PHP (this is the one that does not work) include ("errormessages.php"); $error = ""; if (!$name) { errormessage(); } elseif ($anothercondition) { gotofunction(); } elseif ($anothercondition2) { gotofunction2(); } elseif ($anothercondition3) { gotofunction3(); } function errormessage() { code ....... code ....... } function gotofunction() { code ....... code ....... } function gotofunction2() { code ....... code ....... } function gotofunction3() { code ....... code ....... } ?> <?PHP $ipexists = checkforduplicates(); switch (true) { case (!$name): showentries(); break; case (!$ipexists): writerecord($date, $name, $email, $comment); break; case ($ipexists): duplicatemessage(); break; } function checkforduplicates() { code .......; } showentries() { code .......; } writerecord($date, $name, $email, $comment) { code .......; } duplicatemessage() { code .......; } ?> ----- Original Message ----- From: "Jon Haworth" <jhaworth@witanjardine.co.uk> To: "'Beauford.2002'" <beauford.2002@rogers.com>; "PHP General" <php-general@lists.php.net> Sent: Friday, December 20, 2002 11:05 AM Subject: RE: [PHP] Problem with functions > Hi, > > > I keep getting errors in my script that says 'x' function > > is undefined or 'y' function is undefined. I defined it as > > 'function test ($a, $b)' and call it using 'test($a, $b)' > > You need to post code :-) > > Try this: > > <?php > > function test ($a, $b) > { > echo "I am the test function<br />"; > echo "a is $a<br />"; > echo "b is $b<br />"; > } > > test(1, 2); > > ?> > > Cheers > Jon > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.general (#129012) next »