Understanding Variable Scope in Functions

PHP functions work differently than many other programming languages because they are globally defined. Likewise, the rules of scope may appear different than the norm, but they are not.

Functions can access only global variables and variables defined in them, which are known as local variables. You define global variables with the define() function that was discussed in Chapter 4. Global variables can be defined inside functions, which make them available only after calling the containing function. This behavior has benefits and problems. The benefit is that you can define conditional global variables at run time. The problem is that you can have more than one mechanism that returns values from a function, ...

Get Oracle Database 10g Express Edition PHP Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.