Req #75023 [Opn->Sus]: File Private Visibility Type

From: Date: Fri, 04 Aug 2017 22:56:06 +0000
Subject: Req #75023 [Opn->Sus]: File Private Visibility Type
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-210493@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75023&edit=1 ID: 75023 Updated by: stas@php.net Reported by: php at haravikk dot me Summary: File Private Visibility Type -Status: Open +Status: Suspended Type: Feature/Change Request Package: *General Issues PHP Version: Next Major Version Block user comment: N Private report: N New Comment: Thank you for your interest in PHP and for submitting a feature request. Please be aware that due to the magnitude of change this request requires, it would be necessary to discuss it on PHP Internals list (internals@lists.php.net) as an RFC. Please read the guide about creating RFCs here: https://wiki.php.net/rfc/howto If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list (http://php.net/mailing-lists.php) and/or solicit help from one of the experienced developers. Please to not consider this comment as a negative view on the merits of your proposal - every proposal which requires changes of certain magnitude, even the very successful and widely supported ones, must be done through the RFC process. This helps make the process predictable, transparent and accessible to all developers. Previous Comments: ------------------------------------------------------------------------ [2017-08-02 11:13:29] php at haravikk dot me Description: ------------ While a lot of classes written for PHP tend towards one class per file, it is often still useful to keep supporting classes within the same file. For example, say I have an abstract type Object, with two concrete variations; Object_Wrapper and Object_Instance. If these are only obtained through static methods on Object, then there is no need to separate these out into their own files, as they should never be called for directly (i.e- all interaction occurs via Object). However, because of PHP's visibility model, interaction between these types may still require public methods that the developer doesn't actually want to be public. What is really needed is the ability to specify a file-private visibility type, making a method/property/constant visible only to other code/types from the same file. In the example code below, both Object_Wrapper and Object_Instance have public constructors, but shouldn't really need to, i.e- it would be preferable if these were limited to the same file only, to prevent accidental creation of one of these directly, rather than through Object indirectly as designed. Test script: --------------- <?php abstract class Object { public static function create() { return new Object_Wrapper(new Object_Instance()); } } /** Wraps some useful functionality around an Object_Instance, e.g- if the instance provides some baseline functionality, with wrappers providing more specifics. */ class Object_Wrapper extends Object { private $object; /** @internal */ function __construct(Object_Instance $object) { $this->object = $object; } } class Object_Instance extends Object { /** @internal */ function __construct() { /* Object is pretty useless right now */ } } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75023&edit=1

« previous php.bugs (#210493) next »