Reputation: 19989
Now that 5.4.x is at EOL, we are making the jump to 5.6 so we can actually get back to working on features. However we are running into the:
Strict standards: Declaration of Hobis_Api_Cache::get() should be compatible with Memcached::get($key, $cache_cb = NULL, &$cas_token = NULL, &$udf_flags = NULL)
...warning.
It looks like a major SF2 bundle: 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 as high priority. However as more users are compelled to update to 5.5+ due to 5.4 EOL, I think this issue will need to be addressed sooner rather than later.
So my question is, has anyone figured out an elegant solution to this issue?
Our in-house middleware (Hobis_Api) protects us a little bit, in that I can break out the set
and get
functions and put them in their own class, which does not extend Memcached, then treat them as wrapper functions based on current php version id, something like this:
// 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);
}
}
}
But obviously this will be a PITA b/c I have to update all the calling code from $cache->set()
to Hobis_Api_Cache_Package::set()
Upvotes: 3
Views: 390
Reputation: 19989
Thx to Paul's suggestion, here's the end result:
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;
}
}
}
This will only work if you extended the memcached class with your own class, if not, then you may want to consider adding your own class.
Upvotes: 1