FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » out of sheer curiosity...
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: out of sheer curiosity... [message #177635 is a reply to message #177633] Wed, 11 April 2012 20:30 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 4/11/2012 4:17 PM, Thomas Mlynarczyk wrote:
> Jerry Stuckle schrieb:
>
>>> MyDatabaseSingleton::getInstance() ?
>>
>> What if you don't want a singleton? Many times I've had the need to
>> access different databases, for instance. You are limiting the
>> versatility of the class.
>
> MyDatabase::getConnection( $id )
>

Which once again doesn't reuse an existing connection, nor does it
specify what connection is being used. Which host? Which database?

If it's defined within the MyDatabase class, you're restricted to that
one connection/database. If it's defined in the serialized class,
you've limited the usefulness of that class.

All is resolved by passing a database object in the constructor of the
class. You are using the object the program wants - not one predefined
by the class itself.

>> By definition you can pass arguments to the constructor. That's why
>> unserialize() is not a good implementation.
>
> But how would you pass any constructor arguments to an unserialize()
> function anyway? You cannot be sure what the string to be unserialized
> really contains, so how would you know which constructor arguments to
> pass? This could be a job for __set_state(): unserialize() then wouldn't
> create objects, but simply call the __set_state() method on the class in
> question, passing the unserialized state information and leave it to
> that method to reconstruct the actual object. But this does not seem to
> be the way PHP works.
>
> Greetings,
> Thomas
>

Which is a big problem with unserialize(). Other languages handle it
quite well by having different constructors available. For instance,
there could be a constructor which takes the serialized object and an
array (or variable arg list) which would unserialize the data and use
the additional arguments.

But problems like this make almost any but the simplest objects useless
for any type of serialization.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: 5.4 windows installer.
Next Topic: Does PHP5 treat $_SERVER['PHP_AUTH_USER']) differently?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 14:32:47 GMT 2024

Total time taken to generate the page: 0.05378 seconds