php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joelm at fb dot com
New email:
PHP Version: OS:

 

 [2014-08-05 16:17 UTC] joelm at fb dot com
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. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-05 16:32 UTC] joelm@php.net
-Type: Documentation Problem +Type: Bug
 [2014-08-18 07:49 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2014-08-18 07:49 UTC] stas@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
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 Dec 30 14:01:28 2024 UTC