Subcookies, the PHP version

As a follow-up to my last article, Take your cookies to the next level with Subcookies, I wrote a PHP equivalent.

You can download the PHP file here as a Zip archive. The file contains two classes: CookieJar and SubCookieJar. Both work in the same way as their Javascript counterparts from the previous article. There are a few things to notice though:

  $subcookies = array (

Also, note this little oddity:

if (CookieJar::fetch('admin'))
$a = SubCookieJar::fetch('admin','name');
$b = SubCookieJar::fetch('admin','homepage');
$c = SubCookieJar::fetch('admin','age').'';
$d = CookieJar::fetch('admin');
print $a;
print '<br></br>';
print $b;
print '<br></br>';
print $c;
print '<br></br>';
print $d;

The variable $c will not contain a value! I’m not sure why, ‘cause I fetched the value before crumbling the subcookie, but it’s not there. If anyone knows why this happens, please let me know.

For more information about the principles of subcookies, read my last article.