Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 25th, 2008, 02:07 AM
Registered User
 
Join Date: Dec 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Static Scope

Hi,

I have read the manual entry on static scope, and I still don't really get it. I understand the basic idea, which is that it allows variable to persist once the function has finished running. But, well. The PHP manual's example is this:

Code:
<?php
function test()
{
    static $a = 0;
    echo $a;
    $a++;
}
?>
I don't understand why it only sets $a to 0 once. Isn't the variable still static when it is being added to? I guess, static variable declarations are only done once, and operations, since they cannot be static, are performed as many times as the function runs ... but I still don't really get it. For example, how does PHP know how many times the function has run? Also, well, I guess I was just looking for an explanation of scope in different words to make it a bit more clear.

Thanks in advance,
JaneDean








Similar Threads
Thread Thread Starter Forum Replies Last Post
non-static reports to static html files miamikk ASP.NET 2.0 Basics 0 June 4th, 2007 01:48 PM
"Out of scope" var??? yankleber XSLT 2 March 31st, 2007 03:53 AM
what is the scope of PHP raaj Beginning PHP 1 February 13th, 2007 12:51 AM
the scope of variable ccj_999 C++ Programming 9 October 26th, 2006 10:35 AM
"Recordset Scope" Nitin_sharma Classic ASP Databases 5 September 23rd, 2004 05:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.