Registry class question.

Hi,

I've build a registry class to store settings I need to use in several
other classes.

Currently I've set it up with a static array in the registry class and
using two methods to access the settings and values
storeSetting($key,$value) {
$this->_settings[$key] = $value;
}

getSetting($key) {
return $this->_settings[$key];
}

The question is what the pros and cons are compared to setting a new
property with the value, like:

storeSetting($key,$value) {
$this->$key = $value;
}

and then instead of calling getSetting, you just use
$this->Registry->property

--
Peter van der Does

GPG key: E77E8E98

IRC: Ganseki on irc.freenode.net
Twitter: [at] petervanderdoes

WordPress Plugin Developer
Blog: http://blog.avirtualhome.com
Forums: http://forums.avirtualhome.com
Twitter: [at] avhsoftware

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Peter van der Does [ Fr, 26 Februar 2010 21:17 ] [ ID #2033554 ]

Re: Registry class question.

On 26 February 2010 20:17, Peter van der Does <pvanderdoes [at] gmail.com> wrote=
:
> Hi,
>
> I've build a registry class to store settings I need to use in several
> other classes.
>
> Currently I've set it up with a static array in the registry class and
> using two methods to access the settings and values
> storeSetting($key,$value) {
> =C2=A0$this->_settings[$key] =3D $value;
> }
>
> getSetting($key) {
> =C2=A0return $this->_settings[$key];
> }
>
> The question is what the pros and cons are compared to setting a new
> property with the value, like:
>
> storeSetting($key,$value) {
> =C2=A0$this->$key =3D $value;
> }
>
> and then instead of calling getSetting, you just use
> $this->Registry->property
>
> --
> Peter van der Does
>
> GPG key: E77E8E98
>
> IRC: Ganseki on irc.freenode.net
> Twitter: [at] petervanderdoes
>
> WordPress Plugin Developer
> Blog: http://blog.avirtualhome.com
> Forums: http://forums.avirtualhome.com
> Twitter: [at] avhsoftware
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

You can use __get(), __set(), etc. instead.

That way, $this->Registry->property can work as you want.

Something PHP is missing is the ability to have __get()/__set()/etc.
available on a static class, so you have to have an instance of the
class and then all that that entails. Singleton pattern most likely.
__getStatic(), __setStatic() (like we have __callStatic() ) would
certainly help.

Regards,

Richard.

--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Richard Quadling [ Sa, 27 Februar 2010 10:39 ] [ ID #2033600 ]
PHP » gmane.comp.php.general » Registry class question.

Vorheriges Thema: mysqli_connect problem
Nächstes Thema: Help preserving sentence structure