Req #44290 [Opn->Sus]: Request for package access control system
| From: | requinix@php.net | Date: | Mon, 29 Apr 2019 21:16:54 +0000 |
| Subject: | Req #44290 [Opn->Sus]: Request for package access control system | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220659@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=44290&edit=1
ID: 44290
Updated by: requinix@php.net
Reported by: mr at segtel dot dk
Summary: Request for package access control system
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: All
PHP Version: 6CVS-2008-02-29 (CVS)
Block user comment: N
Private report: N
New Comment:
The problem is that PHP then has to check who is trying to access what at runtime. That's
expensive.
This request is beyond the scope of what can be handled on this bug tracker. Anyone interested in
this idea should check out the RFC process. https://wiki.php.net/rfc/howto
Previous Comments:
------------------------------------------------------------------------
[2019-04-29 19:09:15] pharaun dot mizzrym dot 86 at gmail dot com
I would love that feature as well. I would have loved namespaces to be implemented that way, but it
seems like nowdays those are most commonly used for autoloaders to find the scripts inside a folder
structure (psr-4).
I'd like to have "package" work similar to a namespace though, so it'll work
easier across multiple files, but with visibility on classes.
Example code:
-------------
<?php
package App\User;
namespace App\User\Some\Namespace;
// not available outside package "App\User"
private class UserRepository {
...
}
<?php
package App\User;
namespace App\User\Some\Other\Namespace;
use App\User\Some\Namespace\UserRepository;
// available outside package
public class UserFactory {
private function getUserRepository(): UserRepository {
return new UserRepository(); // works, because it's in the same package
}
...
}
Expected result:
----------------
<?php
// no package, no namespace
// or different package
// or just namespace without package
use App\User\Some\Namespace\UserRepository; // will cause error (private class)
use App\User\Some\Other\Namespace\UserFactory; // works (public class)
It would allow developers to "hide" classes intended for use inside a part of a program
(module, bundle or similar) only and enforce the use of design patterns like factories or facades
for where it is deemed necessary.
It would deny unintended uses of classes and reduce the possibility of unwanted dependencies.
Also, as a minor quality of life improvement, it would allow IDE developers to reduce the amount of
possible classes shown after typing "new", which can be quite a lot in big projects,
although only a few are actually intended to be used alongside "new", outside the
'package' they come from.
------------------------------------------------------------------------
[2008-02-29 11:06:39] mr at segtel dot dk
Description:
------------
I would like to request a package access control system to accompany public, private and protected
as defined by OMG for UML.
Reproduce code:
---------------
package my_package {
class some_class {
package $var;
}
class other_class {
private $obj;
public function __construct() {
$this->obj = new some_class();
}
public function do_something() {
print $this->obj->var;
}
}
}
Expected result:
----------------
The above should work. my_package::some_class::var is accessible by other classes inside the
my_package package whereas any other class does not have access.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=44290&edit=1