Hi.

--On 05.09.2002 15:12 -0700 Pascal Van Hecke wrote:

> Alternatives here:
> PHP does allow for a varying number of parameters, but
> it's a bit ugly again.  In the constructor, you could
> test on the number of parameters but this would still
> allow only one implementation with 1 parameter, only
> one implementation with 2 parameters, etc...
> 
> Maybe an extra parameter would be better:
> function CArticle ($par_constructortype = "id",
> $par_parameter_array)
> {
>   if ($par_constructortype="id")
>   {
>   ...
>   }
>   if ($par_constructortype="name")
>   {
>   ...
>   }
> }
> A possible problem with the last implementation is
> that overriding the constructor in an inherited class
> becomes a bit more complex?
> 
> Torben, Philipp and other users of the extended
> MidgardClasses, maybe you could give your opinion
> here?

Well, I personally would prefer the Variable Argument List solution, as
long as you can safly distinguish the parameters (should be no
problem). The logic has to be written only once, because your derived
classes can use the CArticle Constructor to do the work, something like
this:

function CMyArticle ($par1, $par2) {
    if (! CArticle::CArticle($par1, $par2))
    {
        $this = false;
        return false;
    }
    // Now you have the Article's ID in $this->id and the
    // Midgard/CArticle Object Methods available to do some further
    // custom initialisation, for example:
    $this->myvar = $this->parameter("mydomain","myvar");
}

Saves you a lot of hazzle.

Be aware, that you cannot overload constructors in PHP. If you write
two CArticle Constructors in the CArticle class, only the latter is
used. I'm not sure how this is in functions though, it is quite
possible, that you can overload functions.


Live long and prosper!
Torben Nehmer

--
Torben Nehmer, Munich, Germany
http://www.nathan-syntronics.de, mailto:[EMAIL PROTECTED]
PGP Public Key: https://www.link-m.de/pgp/t.nehmer.asc

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to