Re: getting variables from other functions
| From: | Jason Wong | Date: | Sun, 21 Jul 2002 04:09:35 +0000 |
| Subject: | Re: getting variables from other functions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-108691@lists.php.net to get a copy of this message | ||
On Sunday 21 July 2002 06:20, Tim Luoma wrote:
> I am just getting started with functions, and have checked the manual
> and Core PHP Programming but I'm still missing something.
>
>
> I have two functions in the same PHP file
>
> BTW "$SEARCHDATE" is in this format YYYYMMDD such as 20020720 for July
> 20th, 2002
>
>
> function set_search_info ($SEARCHDATE)
> {
> global $SEARCHYEAR ;
> global $SEARCHMONTH ;
> global $SEARCHDAY ;
> $SEARCHYEAR = substr("$SEARCHDATE", 0,4);
> $SEARCHMONTH = substr("$SEARCHDATE", -4,-2);
> $SEARCHDAY = substr("$SEARCHDATE", -2);
> }
>
>
>
> function get_yesterday_info ($YESTERDAY)
> {
>
> global $YESTERDAYHUMAN ;
> global $YESTERDAYLINK ;
> global $PREVIOUSCOMMENT ;
> global $LINKBACK ;
>
> $YESTERDAYHUMAN = strftime("%B %d
> %Y",mktime(0,0,0,$SEARCHMONTH,$SEARCHDAY-1,$SEARCHYEAR));
>
> $YESTERDAYLINK = "<< <a
> href=\"$SCRIPT?$YESTERDAY\">$YESTERDAYHUMAN</a>";
>
> $PREVIOUSCOMMENT = Exec("/usr/bin/rdjpgcom images/$YESTERDAY.jpg");
>
> $LINKBACK = "yes" ;
> }
>
>
>
> But $YESTERDAYHUMAN keeps getting set to: November 29 1999 even though
> $SEARCHYEAR and $SEARCHMONTH and $SEARCHDAY are set properly outside of
> get_yesterday_info
Did you print out $SEARCHMONTH & $SEARCHDAY to see what values they contained?
This is a basic debugging technique that everyone should use.
If you had did that you will see that they are both empty. Which means that
you forgot to declare them as global.
--
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
/*
Are you sure the back door is locked?
*/