php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57118 Boolean type not maintained
Submitted: 2006-06-29 14:04 UTC Modified: 2006-06-29 15:02 UTC
From: michael at apison dot com Assigned:
Status: Not a bug Package: memcache (PECL)
PHP Version: 5.1.2 OS: Mandriva 2006
Private report: No CVE-ID: None
 [2006-06-29 14:04 UTC] michael at apison dot com
Description:
------------
Hi there,

I am having a problem with boolean variables stored in the cache.  They are converted to strings, making it impossible to check them against type when comparing (===) the results.

Thanks

Michael

Reproduce code:
---------------
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_var = true;
$tmp_var2 = false;


$memcache->set('key1', $tmp_var, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$memcache->set('key2', $tmp_var2, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";


$get_result = $memcache->get('key1');
echo "Data from the cache:<br/>\n";
var_dump($get_result);

$get_result = $memcache->get('key2');
echo "<br />Data from the cache:<br/>\n";
var_dump($get_result);

Expected result:
----------------
Server's version: 1.1.12
Store data in the cache (data will expire in 10 seconds)
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
bool(true)
Data from the cache:
bool(false)

Actual result:
--------------
Server's version: 1.1.12
Store data in the cache (data will expire in 10 seconds)
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
string(1) "1"
Data from the cache:
string(0) ""

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-29 14:28 UTC] tony2001 at phpclub dot net
This is the way it works and it's expected.
How are you going to distinguish between FALSE aka "something went wrong and we got an error" and FALSE aka "this is what I expected to get" ?
 [2006-06-29 14:41 UTC] michael at apison dot com
Shoot, of course!

Would an exception be appropriate for PHP5 users?
 [2006-06-29 14:47 UTC] tony2001 at phpclub dot net
Well, currently there are no plans to add PHP5 OO features like exceptions etc.
Maybe some day (in memcache 3.0.0?) we'll add them.
 [2006-06-29 15:02 UTC] michael at apison dot com
Makes good sence.  Rockin extention BTW!
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Dec 08 07:03:33 2021 UTC