Edit report at https://bugs.php.net/bug.php?id=61277&edit=1
ID: 61277 User updated by: thbley at gmail dot com Reported by: thbley at gmail dot com Summary: Feature request: Shared Keyword Status: Not a bug Type: Feature/Change Request Package: *General Issues Operating System: All PHP Version: 5.5.0 Block user comment: N Private report: N New Comment: I think it shouldn't be a big issue to get a small portion of the apc or memcache code in the core and make it stable. In the end of 2005, there was the decision to include apc in the core. So I think it is not a bad idea to look at this again. Previous Comments: ------------------------------------------------------------------------ [2012-03-05 03:55:12] ras...@php.net And APC is still not stable and portable enough to include in PHP, so saying to do it like APC doesn't mean much. Doing it like APC means not putting it not the core. And if you want something just like APC, just use APC. Most of the frameworks already do and they include a slower fallback for servers without APC. This is not going to be baked into the object syntax directly since we have all the magic methods you need to hook it in yourself. ------------------------------------------------------------------------ [2012-03-05 02:26:09] thbley at gmail dot com > It is a design decision in PHP not to have such global things in PHP itself. All PHP frameworks are offering some kind of caching with shared disk or shared memory. And I haven't seen a bigger project not using this stuff. It's time to rethink this decision. > - correct locking can be hard I think the way APC does this it, should do it. > - such a feature makes scaling over multiple servers hard It would be enough to have it on one server. For those who want more, can still send the data to memcache. Here is a new example: https://gist.github.com/1975954 ------------------------------------------------------------------------ [2012-03-05 00:19:10] johan...@php.net It is a design decision in PHP not to have such global things in PHP itself. Addon modules (you mentioned apc) can add utilities for this, though. Some reasons include: - PHP can be embedded in any application which might add constrains - correct locking can be hard - such a feature makes scaling over multiple servers hard - it messes with copy-on-write - ... ------------------------------------------------------------------------ [2012-03-04 20:29:34] thbley at gmail dot com update version :-) ------------------------------------------------------------------------ [2012-03-04 20:28:49] thbley at gmail dot com Description: ------------ Feature request: Shared Keyword Declaring class properties as shared makes them accessible for all instances of a PHP script containing the same class name and the same property name. This functionality allows a shared memory access similar to apc_store() and apc_fetch(). The shared property implies the static property. Shared propertes can be accessed without needing an instantiation of the class. If shared is not set for a property, it will be non-shared by default. Shared properties are accessed through the class name or a class name variable or "self", and the Scope Resolution Operator "::". Like any other PHP static variable, shared properties may only be initialized using a literal or constant; expressions are not allowed. So while you may initialize a shared property to an integer or array (for instance), you may not initialize it to another variable, to a function return value, or to an object. Shared memory limit in php.ini: shared_memory_limit = 16M This sets the maximum amount of shared memory in bytes that ALL scripts are allowed to allocate. To have no shared memory limit, set this directive to -1. To have an unlimited shared memory limit, set this directive to 0. When an integer is used, the value is measured in bytes. Shorthand notation may also be used. Shared variables and properties are initialized only in first call of a function/class and every time the shared memory is empty. Scenarios: Caching, performance optimization, counters, progress indicators, parallel queues, etc. Test script: --------------- Foo.php: static class property <? class Foo { shared $cache_shared = "hello"; // public static shared private shared $_cache_shared = "hello"; // private static shared protected shared $_cache_shared = "hello"; // protected static shared shared static $cache_static_shared = "hello"; // invalid, shared implies static $var1 = "hello"; // public non-static non-shared } Foo2.php: static variable <? function some_big_calc() { shared $a = array(); } Scenarios: some_class::$shared_cache = array(...); some_class::$shared_counter++; some_class::$shared_progress = 0.3; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=61277&edit=1