php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #71723 Ability to create internal classes/functions
Submitted: 2016-03-06 15:59 UTC Modified: 2016-03-27 12:32 UTC
From: untuned20 at gmail dot com Assigned:
Status: Suspended Package: *Programming Data Structures
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: untuned20 at gmail dot com
New email:
PHP Version: OS:

 

 [2016-03-06 15:59 UTC] untuned20 at gmail dot com
Description:
------------
The ability to make classes/functions "internal" which would make them only instantiatable and/or callable from within the current root namespace.

This would be helpful when creating a library where you only want classes to be available to other classes within the library. As to someone using the library they wouldn't be able to initiate the class in the library or use it outside of the namespace.

Test script:
---------------
namespace RootSpace\SubSpace;
internal class TestClass {}

---

namespace RootSpace\OtherSpace;
use RootSpace\SubSpace\TestClass;
class AnotherClass {
	public function test(){
		$class = new TestClass();
	}
}

---

namespace MySpace;
use RootSpace\SubSpace\TestClass;
class MyClass {
	public function test(){
		$class = new TestClass();
	}
}

Expected result:
----------------
"AnotherClass" should create an instance of TestClass it "AnotherClass::test()" is called because they share the same root space "RootSpace".

"MyClass" should throw an error when "MyClass::test()" is called because it isn't in the root space "RootSpace"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-27 12:32 UTC] krakjoe@php.net
-Status: Open +Status: Suspended
 [2016-03-27 12:32 UTC] krakjoe@php.net
For this kind of change, an RFC is required.

Please see: https://wiki.php.net/rfc/howto
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Dec 02 16:03:40 2021 UTC