From: Operating system: All PHP version: 5.4.0 Package: *General Issues Bug Type: Feature/Change Request Bug description:Feature request: Shared Keyword
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 bug report at https://bugs.php.net/bug.php?id=61277&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=61277&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=61277&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=61277&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=61277&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=61277&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=61277&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=61277&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=61277&r=needscript Try newer version: https://bugs.php.net/fix.php?id=61277&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=61277&r=support Expected behavior: https://bugs.php.net/fix.php?id=61277&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=61277&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=61277&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=61277&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=61277&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=61277&r=dst IIS Stability: https://bugs.php.net/fix.php?id=61277&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=61277&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=61277&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=61277&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=61277&r=mysqlcfg