|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75023 File Private Visibility Type
Submitted: 2017-08-02 11:13 UTC Modified: 2017-08-04 22:56 UTC
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: php at haravikk dot me Assigned:
Status: Suspended Package: *General Issues
PHP Version: Next Major Version OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at haravikk dot me
New email:
PHP Version: OS:


 [2017-08-02 11:13 UTC] php at haravikk dot me
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:

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 */ }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-02 11:26 UTC]
-Package: PHP Language Specification +Package: *General Issues
 [2017-08-04 22:56 UTC]
-Status: Open +Status: Suspended
 [2017-08-04 22:56 UTC]
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 ( as an RFC. Please read the guide about creating RFCs here:
If you haven't had experience with writing RFCs before, it is advised to seek guidance on the Internals list ( 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.
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Dec 04 18:01:23 2020 UTC