rfc:locked-classes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
rfc:locked-classes [2019/03/10 18:23] imsoprfc:locked-classes [2019/03/11 11:03] – Fix formatting in reflection section nikic
Line 3: Line 3:
   * Date: 2019-03-10   * Date: 2019-03-10
   * Author: Rowan Collins [IMSoP], rowan.collins@gmail.com   * Author: Rowan Collins [IMSoP], rowan.collins@gmail.com
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: http://wiki.php.net/rfc/locked-classes   * First Published at: http://wiki.php.net/rfc/locked-classes
  
Line 13: Line 13:
  
 Changing this behaviour for all objects would be a significant change to the language, with the potential to break a large amount of existing code. However, code written with no intention of using this dynamic behaviour would benefit from a way to switch it off. Changing this behaviour for all objects would be a significant change to the language, with the potential to break a large amount of existing code. However, code written with no intention of using this dynamic behaviour would benefit from a way to switch it off.
 +
 +While this can be achieved through strategic use of the ''%%__set%%'', ''%%__get%%'', and ''%%__unset%%'' magic methods, this is long-winded, hard to optimise, and interferes with other uses of those methods.
  
 ===== Proposal ===== ===== Proposal =====
Line 67: Line 69:
  
 Since the proposed modifier applies to a class, not an instance, it would be confusing to use the keyword "sealed" in this sense, so the synonym "locked" has been chosen instead. Since the proposed modifier applies to a class, not an instance, it would be confusing to use the keyword "sealed" in this sense, so the synonym "locked" has been chosen instead.
 +
 +The name "strict" was also considered, but this could mean a variety of things, and might mislead users into thinking other types of "strictness" will apply to the class.
  
 ===== Backward Incompatible Changes ===== ===== Backward Incompatible Changes =====
 +The keyword "locked" will become "semi-reserved", on the same list as "final" and "abstract".
 +
 No existing code will change behaviour, since the modifier must be explicitly added. No existing code will change behaviour, since the modifier must be explicitly added.
  
Line 86: Line 92:
 The following additions will be made to expose the new flag via reflection: The following additions will be made to expose the new flag via reflection:
  
-* New constant ReflectionClass::IS_LOCKED to expose the bit flag used for locked classes +  * New constant ReflectionClass::IS_LOCKED to expose the bit flag used for locked classes 
-* The return value of ReflectionClass::getModifiers() will have this bit set if the class being reflected is locked +  * The return value of ReflectionClass::getModifiers() will have this bit set if the class being reflected is locked 
-* Reflection::getModifierNames() will include the string "locked" if this bit is set +  * Reflection::getModifierNames() will include the string "locked" if this bit is set 
-* A new ReflectionClass::isLocked() method will allow directly checking if a class is locked+  * A new ReflectionClass::isLocked() method will allow directly checking if a class is locked
  
 ===== Unaffected PHP Functionality ===== ===== Unaffected PHP Functionality =====
rfc/locked-classes.txt · Last modified: 2019/06/04 18:56 by imsop