On Thu, 2008-06-19 at 10:53 -0700, James Ausmus wrote:
> On Thu, Jun 19, 2008 at 7:54 AM, Robert Cummings <[EMAIL PROTECTED]> wrote:
> <snip>
> > Ummm, yes it is :) Static variables have persistence beyond the function
> > call and thus beyond the function scope itself.
> 
> 
> Umm, no it's not. Static variables have persistence, but are scoped
> just like normal variables -
> http://us2.php.net/manual/en/language.variables.scope.php, about 10%
> down the page, under the header "Using static variables" - "A static
> variable exists only in a local function scope, but it does not lose
> its value when program execution leaves this scope."

So returning the variable exports it's value outside the scope...
semantics.

Doh, just reviewed the code I updated for Byron and I forgot to return
$con.

> Three simple ways to fix this:
> 
> 1. Declare $con as a global
> 2. Return $con from the initialization function, and pass it in as a
> parameter to all functions that need it

Yeah, that's it :)

> 3. Put all these functions into a class, and make $con a member of the
> class, so it could be referenced by $this->con
> 
> >From the looks of your code, #3 is really your right answer, as it
> appears you're trying to create a set of functions that are related,
> and need to shared common data - you've got yourself an object...
> Otherwise, if you don't want to go OOP, then go with #2, as #1 is the
> most dirty way of fixing the problem. :)

Hear, hear.

Cheers,
Rob.
-- 
http://www.interjinn.com
Application and Templating Framework for PHP


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to