PHP 5.6 - Memcached - 严格的标准
PHP 5.6 - Memcached - Strict Stadards
现在 5.4.x 已停产,我们正在跳转到 5.6,这样我们才能真正回到功能上。但是我们 运行 进入:
Strict standards: Declaration of Hobis_Api_Cache::get() should be compatible with Memcached::get($key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL)
...警告。
它看起来像一个主要的 SF2 捆绑包:LswMemcacheBundle had the same issue, but their "fix" was to switch APIs from Memcached to Memcache, which may work, but we chose Memcached for a reason. However the maintainers of the php wrapper for memcached apparently don't see fixing this issue 具有高优先级。然而,由于 5.4 停产,越来越多的用户被迫更新到 5.5+,我认为这个问题需要尽快解决。
所以我的问题是,有没有人想出一个优雅的解决方案来解决这个问题?
我们的内部中间件 (Hobis_Api) 保护了我们一点点,因为我可以分解 set
和 get
函数并将它们放在自己的 class,它不扩展 Memcached,然后根据当前 php 版本 ID 将它们视为包装函数,如下所示:
// Now
class Hobis_Api_Cache extends memcached
{
public function set($key, $value, $expiry = self::EXPIRY_DEFAULT) {}
}
// Proposed
class Hobis_Api_Cache_Package
{
public static function set($key, $value, $expiry, $udfs)
{
$cache = new Memcached;
if (PHP_VERSION_ID < 50500) {
$cache->set($key, $value, $expiry);
} else {
$cache->set($key, $value, $expiry, $udfs);
}
}
}
但显然这将是一个 PITA b/c 我必须将所有调用代码从 $cache->set()
更新为 Hobis_Api_Cache_Package::set()
感谢 Paul 的建议,这是最终结果:
class Hobis_Api_Cache extends memcached
{
/**
* Magic method override so we can use our version of get/set
* Otherwise default get/set will break in php 5.5+
*
* @param string
* @param array
*/
public function __call($name, $arguments)
{
switch ($name)
{
// Override due to 5.5+ using php-memcache 2.2
case 'get':
$this->myGet($arguments);
break;
// Override due to 5.5+ using php-memcache 2.2
case 'set':
$this->mySet($arguments);
break;
}
}
}
这仅在您使用自己的 class 扩展 memcached class 时有效,否则,您可能需要考虑添加自己的 class.
现在 5.4.x 已停产,我们正在跳转到 5.6,这样我们才能真正回到功能上。但是我们 运行 进入:
Strict standards: Declaration of Hobis_Api_Cache::get() should be compatible with Memcached::get($key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL)
...警告。
它看起来像一个主要的 SF2 捆绑包:LswMemcacheBundle had the same issue, but their "fix" was to switch APIs from Memcached to Memcache, which may work, but we chose Memcached for a reason. However the maintainers of the php wrapper for memcached apparently don't see fixing this issue 具有高优先级。然而,由于 5.4 停产,越来越多的用户被迫更新到 5.5+,我认为这个问题需要尽快解决。
所以我的问题是,有没有人想出一个优雅的解决方案来解决这个问题?
我们的内部中间件 (Hobis_Api) 保护了我们一点点,因为我可以分解 set
和 get
函数并将它们放在自己的 class,它不扩展 Memcached,然后根据当前 php 版本 ID 将它们视为包装函数,如下所示:
// Now
class Hobis_Api_Cache extends memcached
{
public function set($key, $value, $expiry = self::EXPIRY_DEFAULT) {}
}
// Proposed
class Hobis_Api_Cache_Package
{
public static function set($key, $value, $expiry, $udfs)
{
$cache = new Memcached;
if (PHP_VERSION_ID < 50500) {
$cache->set($key, $value, $expiry);
} else {
$cache->set($key, $value, $expiry, $udfs);
}
}
}
但显然这将是一个 PITA b/c 我必须将所有调用代码从 $cache->set()
更新为 Hobis_Api_Cache_Package::set()
感谢 Paul 的建议,这是最终结果:
class Hobis_Api_Cache extends memcached
{
/**
* Magic method override so we can use our version of get/set
* Otherwise default get/set will break in php 5.5+
*
* @param string
* @param array
*/
public function __call($name, $arguments)
{
switch ($name)
{
// Override due to 5.5+ using php-memcache 2.2
case 'get':
$this->myGet($arguments);
break;
// Override due to 5.5+ using php-memcache 2.2
case 'set':
$this->mySet($arguments);
break;
}
}
}
这仅在您使用自己的 class 扩展 memcached class 时有效,否则,您可能需要考虑添加自己的 class.