You are here: Re: Create only one instance of Object « All PHP « IT news, forums, messages
Re: Create only one instance of Object

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация