phpCA client

Tim Yardley liquid@haveheart.com
Tue, 30 Dec 2003 19:19:36 -0600


First off, congratulations guys on making this into a nicely extensible
system.

I was looking at memcached-client-php-0.1.2.tar.gz, particularly at the get
function of said release.  It seems like instead of return'ing false in the
case that an object is not found, it would make sense to instead return the
php NULL constant.  The desire after fetching something from the cache is to
determine if it was returned by the cache, not to check its value.  So, with
that in mind... Here are the ways we can check that.

Currently returning FALSE when an item doesn't exist gives you the
following:

<?
$memcache->add('false', FALSE);
$memcache->add('true', TRUE);

// object is defined... So we want it to say yes on the first one
$foo = $memcache->get('false');

// this one prints
if (isset($foo)) {
  echo 'got it';
}

// this one does not print
if ($foo) {
  echo 'got it';
}

// this one does not print
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

// object is defined and true... So we want it to say yes here.
$foo = $memcache->get('true');

// this one prints
if (isset($foo)) {
  echo 'got it';
}

// this one prints
if ($foo) {
  echo 'got it';
}

// this one prints
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

// these should all fail
$foo = $memcache->get('idontexist');

// this one prints, incorrectly
if (isset($foo)) {
  echo 'got it';
}

// this one does not print
if ($foo) {
  echo 'got it';
}

// this one does not print
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

?>

Returning NULL when it doesn't exist will give you the following:
<?
$memcache->add('false', FALSE);
$memcache->add('true', TRUE);

// object is defined and false... So we want it to say yes to the first one.
$foo = $memcache->get('false');

// this one prints
if (isset($foo)) {
  echo 'got it';
}

// this one does not print
if ($foo) {
  echo 'got it';
}

// this one does not print
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

// object is defined and true.. So we want it to say yes to all these here.
$foo = $memcache->get('true');

// this one prints
if (isset($foo)) {
  echo 'got it';
}

// this one prints
if ($foo) {
  echo 'got it';
}

// this one prints
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

// these should all fail
$foo = $memcache->get('idontexist');

// this one does not print
if (isset($foo)) {
  echo 'got it';
}

// this one does not print
if ($foo) {
  echo 'got it';
}

// this one does not print
if (isset($foo) && $foo) {
  echo 'got it';
}
unset($foo);

?>

Basically, it boils down to the fact that we want to check if the object was
returned and not check it's value... So that means that the proper way to
check that would be isset($foo), but... That will fail in the case that it
is not defined.  This may affect more than just the PHP client, thoughts?
Hopefully I didn't mistype my test cases as I wrote this.

Did you follow me on that?

/tmy