RE: [PHP] have some free time?
> -Original Message- > From: Kyle Babich [mailto:[EMAIL PROTECTED] > Sent: 02 July 2003 00:19 > > I think this is short example of my problem... > > > $name = 'kyle'; > > function hello() { > print 'hello ' . $name; > $x = 1; > } > > function bye() { > if ($x == 1) print 'x = 1'; > else print 'x != 1'; > } > > hello(); > bye(); > > ?> > > Right now this returns: hello x != 1 > What do I have to do to get bye() to return 'x = 1'? I tried declaring > the x = 1 in hello() global and I tried declaring it static. Possibilities: function hello($x) { print 'hello ' . $name; $x = 1; } function bye($x) { if ($x == 1) print 'x = 1'; else print 'x != 1'; } hello($y); bye($y); -- function hello() { print 'hello ' . $name; $x = 1; return $x; } function bye($x) { if ($x == 1) print 'x = 1'; else print 'x != 1'; } $y = hello(); bye($y); -- function hello() { global $x; print 'hello ' . $name; $x = 1; } function bye() { global $x; if ($x == 1) print 'x = 1'; else print 'x != 1'; } hello(); bye(); Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] have some free time?
You need to return $x out of the function. So do this: function hello() { print 'hello ' . $name; $x = 1; return ($x); } etc Then call it assigned to a variable: $x = hello(); echo $x; bye(); Kyle Babich wrote: I think this is short example of my problem... $name = 'kyle'; function hello() { print 'hello ' . $name; $x = 1; } function bye() { if ($x == 1) print 'x = 1'; else print 'x != 1'; } hello(); bye(); ?> Right now this returns: hello x != 1 What do I have to do to get bye() to return 'x = 1'? I tried declaring the x = 1 in hello() global and I tried declaring it static. On Tue, 01 Jul 2003 17:27:48 -0500, "Kyle Babich" <[EMAIL PROTECTED]> said: Any php programmers out there have a little free time? I've been trying to find the bug in my logging system forever and I've all but given up. If anyone else wants to try their luck then... http://babich.us/log/source/log.php.txt http://babich.us/log/source/config.inc.php.txt http://babich.us/log/source/test.php.txt http://babich.us/log/source/clearLogs.inc.php.txt http://babich.us/log/source/logIpData.inc.php.txt http://babich.us/log/source/logAgentData.inc.php.txt http://babich.us/log/source/logLangData.inc.php.txt I have a feeling that it is an obvious, simple error that I am missing. Anyway, back to the bug hunting... -- Kyle -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] have some free time?
I think this is short example of my problem... Right now this returns: hello x != 1 What do I have to do to get bye() to return 'x = 1'? I tried declaring the x = 1 in hello() global and I tried declaring it static. On Tue, 01 Jul 2003 17:27:48 -0500, "Kyle Babich" <[EMAIL PROTECTED]> said: > Any php programmers out there have a little free time? I've been trying > to find the bug in my logging system forever and I've all but given up. > If anyone else wants to try their luck then... > > http://babich.us/log/source/log.php.txt > http://babich.us/log/source/config.inc.php.txt > http://babich.us/log/source/test.php.txt > http://babich.us/log/source/clearLogs.inc.php.txt > http://babich.us/log/source/logIpData.inc.php.txt > http://babich.us/log/source/logAgentData.inc.php.txt > http://babich.us/log/source/logLangData.inc.php.txt > > I have a feeling that it is an obvious, simple error that I am missing. > Anyway, back to the bug hunting... > -- > Kyle > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php