Understanding Variable Scope in Php

Google+ Pinterest LinkedIn Tumblr +

Is the learning of Variable scope important in any computer language? Yes. Somebody may be learning a computer high-level language for his/her first time and would be finding it interesting. When the person comes to the topic of variable scope, he/she may become annoyed and might not even see the reason for learning variable scope. The reason is that in many documents, variable scope is poorly taught.

If you do not learn variable scope, you will write programs that have errors with the variables and you will not be able to determine the solution. In this article, I introduce you to a series that makes you understand variable scope in PHP.

In order to understand the tutorial series, you need to have basic knowledge in PHP.

It is a 2 part series.

The First Part of the Series
The first part of the series introduces you to variable scope. This part makes the distinction between what is referred to as Local Scope and what is referred to as Global scope. It stresses on the fact that in PHP, local scope is function scope, meaning the use or existence of a variable in the function block in curly braces, distinguishing the function block from other blocks like the if-block.

This part also explains how to use a global scope variable in a local (function) scope in PHP, which makes the PHP use of global scope in local scope different from other languages like C++ and JavaScript.

The Second Part of the Series
Have you ever heard the phrase, “Static Variable”? How do you apply the meaning of the word, static (stationary) to the topic of variable scope? Does it mean that the value of the variable in local scope remains fixed or it is the possibility of using the variable declare inside a local scope outside the local scope, while the variable maintains the last value assigned to it? Can we say that it means a variable declared in local scope as static continues to be alive outside the local (function) scope? The answer to all these questions, are revealed in this part of the series, in simple terms.

The tutorial series, have been written by me. They have been written in a step-by-step fashion. The formatting of the code samples is good with good indentation. So readability is good. In some sites there are missing special characters in a computer language article. You do not find that in this tutorial series. The hyperlinks to the different parts of the series are easily accessible from each part of the series.

Above all, the series is free. After completing the series, you will be able to write more efficient scripts in PHP, avoid variable scope errors and be able to solve problems related to variable scope. Click the following hyperlink to start the series: