Req #32073 [Opn->Dup]: Overloading for static methods and properties
| From: | levim@php.net | Date: | Thu, 08 May 2014 18:00:56 +0000 |
| Subject: | Req #32073 [Opn->Dup]: Overloading for static methods and properties | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-185726@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=32073&edit=1
ID: 32073
Updated by: levim@php.net
Reported by: joh at deworks dot net
Summary: Overloading for static methods and properties
-Status: Open
+Status: Duplicate
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: Scripting Engine problem
Operating System: Linux
PHP Version: 5CVS-2005-02-23 (dev)
Block user comment: N
Private report: N
New Comment:
This is a duplicate of 45002; though that bug is much newer than this one it has gotten
significantly more feedback.
Previous Comments:
------------------------------------------------------------------------
[2005-04-12 14:48:56] 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".
------------------------------------------------------------------------
[2005-02-23 01:58:06] joh at deworks dot net
Description:
------------
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:
---------------
<?php
class Foo {
protected static $readonly = "Read-only member";
public static function __get($name)
{
switch ($name) {
case 'readonly':
return self::$readonly;
break;
default:
break;
}
}
}
echo Foo::$readonly;
Foo::$readonly = "Not possible.";
?>
Expected result:
----------------
Read-only member
Actual result:
--------------
Fatal error: Cannot access protected property Foo::$readonly ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=32073&edit=1