What are the different scopes of variables?

Technology CommunityCategory: PHPWhat are the different scopes of variables?
VietMX Staff asked 4 years ago

Variable scope is known as its boundary within which it can be visible or accessed from code. In other words, it is the context within which a variable is defined. There are only two scopes available in PHP namely local and global scopes.

  • Local variables (local scope)
  • Global variables (special global scope)
  • Static variables (local scope)
  • Function parameters (local scope) When a variable is accessed outside its scope it will cause PHP error undefined variable.