RE: serialize

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Sent this to bedouglas@xxxxxxxxxxxxx but forgot to copy php-general...
> heh. Here it is again.
> 
> I would use a table such as
> Table
>  |_UserData
> 
> Then use objects per user to store the data.
> class User {
>       var TestScore;
>       var ScoreType;
>       ...
>       var Vars;
>       function __construct($TestScore, $ScoreType) {
>             $this->TestScore = $TestScore;
>             $this->ScoreType = $ScoreType;
>       }
>       function __sleep() {
>           $this->Vars = get_object_variables($this);
>      }
>      ...
>      function ListVars() {
>             $MyString = "";
>             ForEach($this->Vars as $key => $value) {
>                   $MyString .= "${key}: ${value}\n";
>             }
>             Return $MyString;
>     }
> }
> $Joe = new User("WhateverScore", "WhateverType");
> $sJoe = Serialize($Joe);
> ...Store it...
> 
> 
> ...Recall it...
> (Variable result = recieved serialized version of $Joe)
> $Joe = unserialize($Result);
> $Results = $Joe->ListVars();

Hi Jake,

I guess this comes down to preference, but I personally simply couldn't
bring myself to store serialized objects in a table in the way you're
describing.

A well-designed database should not only be normalized, but should also be
agnostic of the technology being used to access it.

I don't know enough about whether or not serialize() is a widely implemented
language construct, but I have worked on enough projects where someone in
management has said, "Hey, I know you've done all this work in PHP (or
insert language here), but we've decided we want to rework it in (insert
other language which someone read a glowing article about on some website)"
to shudder at the thought of storing data in a database that perhaps only
one language can access.

It also implies more coding to perform relatively simple recordset
operations such as "give me the average of 'score12' across all things being
scored", etc. Lastly, it locks your DBA (assuming you have one) out of being
able to perform granular updates should the need arise. It's for pretty much
the same reason that I hide under my desk, whimpering, when someone
inevitably suggests storing XML recordsets as XML documents in database
fields.

So, full marks for fully exploiting the potential of objects, but you'll
have to excuse me while I go make a coffee and maybe go for a brisk walk to
get over the case of heebie-jeebies this suggestion gave me. ;-)

Much warmth,

Murray
---
"Lost in thought..."
http://www.planetthoughtful.org

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux