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: Open
Type: Feature/Change Request
Package: *General Issues
Operating System: All
-PHP Version: 5.4.0
+PHP Version: 5.5.0
Block user comment: N
Private report: N
New Comment:
update version :-)
Previous Comments:
------------------------------------------------------------------------
[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