Page 1 of 1

static variables in PHP - or ... ?

Posted: Sat Aug 26, 2006 4:22 pm
by cficando
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Help!!!   

Why won't this simple PHP code work?   

[url]http://www.safediets.org/gettest.php?first=george[/url]

Code: Select all

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
if (isset($_GET['first'])) {
		
		echo $_GET['first'] . "<br>";
		
		if ("B" == "B") {
		$Binc = BCounter();
		echo $Binc . "<br>";
		} 

		
	} else { 
	echo "No get set";
}

	function BCounter() {
		static $Binc = 0;
		$Binc++ ;
		return number_format ($Binc); }

?>
</head>
<body></body></html>
? :idea: ?


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Aug 26, 2006 4:48 pm
by feyd
"B" == "B" is always true, same for the if following it.

As for the if following that, string literals cannot be assigned to.

Posted: Sat Aug 26, 2006 7:29 pm
by cficando
I apologize for the single = where there should have been a double ==. And I am aware that A always equils A.

:? That was not the problem I was trying to solve though. :roll: So, I apologize for wasting your time too.