Re: Re: namespaces?
| From: | Stig S. Bakken | Date: | Sun, 15 Jul 2001 17:27:16 +0000 |
| Subject: | Re: Re: namespaces? | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-794@lists.php.net to get a copy of this message | ||
Erik Hjortsberg wrote:
>
> At 15:27 2001-07-15 +0200, you wrote:
> >Erik Hjortsberg wrote:
> > >
> > > At 14:07 2001-07-15 +0200, you wrote:
> > > >- Return in constructors. For me seems a little bit silly the need off
> > > >providing an extra method to do the work and get the error back.
> > > >$foo = new bar();
> > > >$err = $foo->build(); //or something similar
> > > >if (PEAR::isError($error)) { .. }
> > > >
> > > >while you could simply do:
> > > >$foo = new bar(); // or perhaps something like $foo = new::bar();
> > > >if (PEAR::isError($foo)) { .. }
> > > >
> > > >
> > > >Tomas V.V.Cox
> > >
> > > Hmm, you can always do:
> > > $foo = & bar::new();
> > > if (PEAR::isError($foo)) { .. }
> > >
> > > and do all of your init in new().
> > > Kinda like Smalltalk does it.
> > >
> >
> >With you idea I should do:
> >
> >class Bar {
> > function new($file) {
> > // do things
> > if ($error) {
> > return $error;
> > }
> > return & new Bar;
> > }
> >}
> >
> >Instead of this strange thing I would probably prefer to provide a
> >build() method.
> >
> >Someone some day, posted a curious system to do what I say:
> >class Bar {
> > function Bar() {
> > if ($error) {
> > // overwrite the object
> > $this = $error;
> > }
> > }
> >}
> >
> >But's ok, no more discuss on this topic as it has been clearly rejected
> >:)
>
> Nah, I can't drop it yet. :)
>
> True, it looks kinda awkward, but it has it's points.
> I've done a system for accessing a database through objects (similiar to
> DB_Storage, but with some major differences).
> One of the differences is that getting and creating new objects is made
> through static methods, resulting in that an object with a specific id will
> only be fetched from the database once per request. (The system keeps
> tracks of which objects are "checked" out, thus relieving the sql-server.)
> <code>
> $person1 = & Person::Get(1);
> $person2 = & Person::Get(1);
> </code>
> Both $person1 and $person2 will point to the same object.
> With creating entries it's unlogical to first make an empty object and then
> issuing it a create message. The logical way is to send a Create message to
> the class and let it return a new object if successful.
Most or all of the pear community agrees with you, the problem is that
Zeev doesn't want to make this a feature. There's a thread about it
from two months or so back.
> On another note, for my system I've tried to arrange it for the objects to
> be able to wait with updating the database and do it first when their
> constructors are called (ie when the user already has gotten the page). The
> problem is that database-connections doesn't seem to survive through to the
> shutdown_function. They look alright but fails without an error being
> raised when used. Sure, I can create a new database-connection in the
> shutdown_function, but for a number of reason I don't want that. I sent a
> message to the list a couple of weeks ago, perhaps it was swallowed by the
> list. I'll send it again.
Please do.
- Stig