Understanding PHP Variable Scope


In PHP as in other programming languages, scope identifies areas in a program or script where a given variable is visible. There are many scope rules and here are the most important ones.

  • The native super globals can be viewed anywhere in the program.
  • Constants can be used outside as well as inside functions, i.e., they have global visibility.
  • When you define a global variable in a script, that variable will have visibility in all areas of that script except for inside of functions within that same script.

What a Constant is and how to declare one

What a Constant is and how to declare one

In PHP values that are stored in variables are updated all the time. What happens when you need a value to maintain consistency though? For that you can use constants. Similar to how we can assign a value to a variable, we also assign a value to a constant but the difference is that once you set that constant value, it cannot be modified. Let’s say you want to be sure the values of certain variables will not change in your application.…

Introduction to PHP – Variables and Data Types

We’ve covered a bunch of front end design and programming in some recent posts a la, twitter bootstrap. What about minding the back end? When we talk back end, we talk PHP. What is PHP? It’s a cool programming language efficient in many ways used to communicate with a database, generate sessions and cookies, drum up unique content to serve to a browser, and even interact with third party API’s or Application Programming Interfaces.…