|
Global - Tcl, PHP, Python
PHP, Python, Tcl and a number of other languages have a global keyword. And it's a misnomer in most (if not all) cases.
To the un-initiated, "Global" means "worldwide" or "shared all around". So you would think that if you declare something as global, you're going to be sharing it with the same thing everywhere else. But - sorry - that's not the case. In each of the languages I quoted, global really means "Share this with the variable of the same name in the main program".
What does this mean?
• In Tcl, Python, PHP ... you do NOT need to declare a variable as being global in your main code, even if you want to share it with your procs (Tcl) methods (Python) or functions (PHP) - it is, in effect, automatically global if you want to declare in global in a named block of code
• If you don't want a variable within a named block of code to be shared with the same 'global' variable, you can be reassured that you will not be sharing it simply by omitting any global declaration for it in the named block
• If you want to share a variable between two named blocks of code, you can do so by declaring it as global in BOTH of them ... and this has the side effect that it will also be shared, without any declaration, by any variable that happened to have the same name in your main block of code(written 2008-09-03 00:23:43)
Associated topics are indexed under H105 - PHP - FunctionsY105 - Python - Functions, Modules and PackagesP209 - Subroutines in Perl
Some other Articles
Python 2 to Python 3 / Python 3000 / Py3kHowto - write and manage a news box on your web pagePicturing the rainWhat is running on your network? (tcl and expect)Global - Tcl, PHP, PythonThink before you sendCalling procs in Tcl and how it compares to PerlReceptionServer overloading - turns out to be feof in PHPInjection Attacks - avoiding them in your PHP
|
1889 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38 at 50 posts per page
This is a page archived from The Horse's Mouth at
http://www.wellho.net/horse/ -
the diary and writings of Graham Ellis.
Every attempt was made to provide current information at the time the
page was written, but things do move forward in our business - new software
releases, price changes, new techniques. Please check back via
our main site for current courses,
prices, versions, etc - any mention of a price in "The Horse's Mouth"
cannot be taken as an offer to supply at that price.
Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).
|
|