|
Posted by Rik on 03/09/07 12:48
weetat <weetat.yeo@gmail.com> wrote:
> Hi all ,
>
> I am using php version 4 which did not have private method access.
> How to prevent the user call the object constructor as shown below :
Enforcing a singleton in PHP4 is tricky. I usually end up with some pseu=
do =
code triggerering a (fatal) error in the constructor:
$info =3D reset(debug_backtrace());
if(!isset($info['class'])
|| $info['class'] !=3D get_class($this)
||!isset($info['type'])
||$info['type']!=3D'::'
||!isset($info['function'])
||$info['function']!=3D'getInstance'
){
trigger_error('This is a singleton class, only use =
class::getInstance()', E_USER_ERROR);
}
HTH
-- =
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Navigation:
[Reply to this message]
|