Req #32073 [Com]: Overloading for static methods and properties

From: Date: Thu, 08 May 2014 18:01:40 +0000
Subject: Req #32073 [Com]: Overloading for static methods and properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185727@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 Comment by: levim@php.net Reported by: joh at deworks dot net Summary: Overloading for static methods and properties Status: Duplicate Type: 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: Duplicate of bug 45002 (forgot to prefix with bug to get proper linking) Previous Comments: ------------------------------------------------------------------------ [2014-05-08 18:00:56] levim@php.net This is a duplicate of 45002; though that bug is much newer than this one it has gotten significantly more feedback. ------------------------------------------------------------------------ [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

« previous php.bugs (#185727) next »