|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #32073 Overloading for static methods and properties
Submitted: 2005-02-23 01:58 UTC Modified: 2014-05-08 18:00 UTC
Avg. Score:4.4 ± 0.9
Reproduced:10 of 12 (83.3%)
Same Version:4 (40.0%)
Same OS:5 (50.0%)
From: joh at deworks dot net Assigned:
Status: Duplicate Package: Scripting Engine problem
PHP Version: 5CVS-2005-02-23 (dev) OS: Linux
Private report: No CVE-ID: None
 [2005-02-23 01:58 UTC] joh at deworks dot net
Currently, it is only possible to overload method calls and member accesses of an object. The use of static classes with static methods and members is a good way to organize different parts of an application. Therefore, it would've be convenient to be able to overload static method calls and member accesses as you can do on objects. As a static class member/method cannot have the same name as a normal class member/method, this should be possible.

This would give the developer finer controll over his/her static libraries.

In the provided example, the developer could restrict access to the static member Foo::$readonly.

Reproduce code:
class Foo {

	protected static $readonly = "Read-only member";

	public static function __get($name)
		switch ($name) {
			case 'readonly':
				return self::$readonly;

echo Foo::$readonly;
Foo::$readonly = "Not possible.";

Expected result:
Read-only member

Actual result:
Fatal error: Cannot access protected property Foo::$readonly ...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-12 14:48 UTC] ghostwwinside at gmx dot net
I think the overloading documentation is a bit unclear,
beacause it mention "Class members" and do not restrict
it to "Instance members".
 [2014-05-08 18:00 UTC]
-Status: Open +Status: Duplicate -Package: Feature/Change Request +Package: Scripting Engine problem
 [2014-05-08 18:00 UTC]
This is a duplicate of 45002; though that bug is much newer than this one it has gotten significantly more feedback.
 [2014-05-08 18:01 UTC]
Duplicate of bug 45002 (forgot to prefix with bug to get proper linking)
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Jun 10 18:03:37 2023 UTC