Saturday, July 16, 2005

PHP note: Difference between PHP and Python - scope

Scope in Python is more complex. Firstly, functions. You will encounter local, global and builtin scopes in a function. Local scope is the scope within functions, global scope is the currently running module scope, while builtin scope is the current running python program. Secondly, objects. You will encounter object, class scope. Python searches for variables in sequence of scopes, and looks at a higer level scope when it can't find symbol in the current scope.

Scope in PHP is just simple. Normally you only need a module scope, while in functions there is a local scope. PHP does not search super scopes though. This is somehow because PHP can always find symbols. When variable not defined, PHP will simply set an empty value to it.

No comments: