PHP API suggestion? Maybe?

Ryan T. Dean
Thu, 9 Oct 2003 12:00:43 -0400

Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Oct 09, 2003 at 11:43:33AM -0400, Justin Matlock wrote:
> This isn't necessarily a bug, but it's been annoying me..  Maybe it's not=
> problem, and I'm just missing something obvious (wouldn't be surprising
> these days)...
> Let's say you actually need to store a boolean "false" value in memcached.
> For example, if I run a query, and it returns no records, I store a boole=
> 'false', since that would be different than if I just pulled an int 0 from
> the DB (it means I could find a record, but the result was 0).  Well, whe=
n I
> do a get for this key, the API returns a boolean 'false' (since that's wh=
> was stored in memcached).  This, of course, usually means the key wasn't
> found in a memcached, so my software think the key didn't exist (even tho=
> it did, it was just value'd at false), and it makes another database call.
> Maybe the API should return NULL instead of FALSE if the data doesn't exi=
> since NULL means 'no data'. ?  A configurable option, maybe, since this
> would mean major script changes for most people.
> Of course, this would suck if you were storing a single NULL... but I wou=
> think 'false' would be stored more than NULL.
> Yeah, a way around this would be to never store FALSE as a boolean, and u=
> =3D=3D=3D to differentiate between FALSE and 0...  I just see a big poten=
tial for
> bugs this way, since FALSE =3D=3D 0 is true, but FALSE =3D=3D=3D 0 is unt=
rue.  But, I
> have to be able to tell the difference between "no records found" and "0"
> and "false".
> (I wrapped the memcached API with my own methods, just so I didn't have to
> make mass changes if the API changes).. an example function:
> if ($var =3D (mc_get("keyname") =3D=3D=3D NULL) {
>     $R =3D db_quick("select value from table where foo=3D'bar'");
>     mc_put("keyname",$var);
> }
> As I'm writing this, I realize my db_wrapper could just return a NULL
> instead of a false, and *I* could store the NULL in memcached to signify =
> data.. duh... But it would still be nice if the memcached returned NULL if
> no data found, just in case someone does store a boolean FALSE in there..
> Thoughts?  Or am I just smoking crack?  I just like using NULL as it's
> intended =3D=3D "No Data", since False could be valid data.. :)

Actually, in the coming version 0.2.0 I'll be tossing PEAR error objects=20
on error, instead of a null/false.  This will introduce a new method to=20
memcached-client: isError().  Error messages/codes will be available=20
from the error object using the normal PEAR api ($error>getCode() and=20

So yeah, a fix for this is coming.

		-Ryan T. Dean

Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.3 (FreeBSD)