Req #75023 [NEW]: File Private Visibility Type

From: Date: Wed, 02 Aug 2017 11:13:34 +0000
Subject: Req #75023 [NEW]: File Private Visibility Type
Groups: php.standards 
Request: Send a blank email to standards-+get-1284@lists.php.net to get a copy of this message
From: php at haravikk dot me Operating system: PHP version: Next Major Version Package: PHP Language Specification Bug Type: Feature/Change Request Bug description:File Private Visibility Type 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 bug report at https://bugs.php.net/bug.php?id=75023&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75023&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75023&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75023&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75023&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75023&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75023&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75023&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75023&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75023&r=support Expected behavior: https://bugs.php.net/fix.php?id=75023&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75023&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75023&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75023&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75023&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75023&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75023&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75023&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75023&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75023&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75023&r=mysqlcfg

« previous php.standards (#1284) next »