|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67767 Scope confusion
Submitted: 2014-08-05 16:17 UTC Modified: 2014-08-18 07:49 UTC
From: joelm at fb dot com Assigned: stas (profile)
Status: Closed Package: PHP Language Specification
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2014-08-05 16:17 UTC] joelm at fb dot com

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. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-05 16:32 UTC]
-Type: Documentation Problem +Type: Bug
 [2014-08-18 07:49 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2014-08-18 07:49 UTC]
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

Should be fixed now in new redaction of basic concepts.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 09:01:29 2024 UTC