Doc #67767 [NEW]: Scope confusion

From: Date: Tue, 05 Aug 2014 16:17:55 +0000
Subject: Doc #67767 [NEW]: Scope confusion
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-11412@lists.php.net to get a copy of this message
From: joelm at fb dot com Operating system: PHP version: Irrelevant Package: PHP Language Specification Bug Type: Documentation Problem Bug description:Scope confusion Description: ------------ https://github.com/php/php-langspec/blob/master/spec/04-basic-concepts.md#scope This section and the way "scope" is discussed throughout the spec is confusing. I think there are 3 separate issues at work here. The first issue is whether something is accessible just within part of the code, or whether it's accessible somehow from virtually everywhere in the program. The second issue is when a qualifier (such as "Foo::" where Foo is a class) is required to refer to something, and when it is not required. The third issue is the scope within which another construct of the same kind with the same name cannot be declared (example if you define an instance property $x inside the definition of class C, you cannot define another instance property $x inside that same class definition, though you can define an instance property $x in a class that derives from D). We get very different behavior for variables vs. class constants for examples. For local variables in a regular function (i.e. not a pseudomain), the local variables are only accessible within a given function, no qualifier is needed, and re-definition is not possible really (except for parameters where PHP5 weirdly tolerates multiple parameters with the same name). For class constants, they are accessible virtually everywhere, a qualifier is ALWAYS needed even inside methods of the class, and there cannot be another constant definition with the same name in that same class definition. -- Edit bug report at https://bugs.php.net/bug.php?id=67767&edit=1 --

« previous php.doc.bugs (#11412) next »