Reply to Create only one instance of Object

Your name:

Reply:


Posted by weetat on 03/09/07 09:10

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 :

Thanks
Joshua

class MYSQL_DB
{
var $dbConn = null;

/**
* php4 did not have private access method , only php5
* user can call the function, need to find way not allow it ,
but it better use getInstance() to
* have one database instance only
*/
function MYSQL_DB()
{
global $dbHost, $dbUser, $dbPass, $dbName;
$this->dbConn=&ADONewConnection("mysql"); # create a
connection
$this->dbConn->Connect($dbHost, $dbUser, $dbPass, $dbName);
}

/**
* @desc get only one instance created
*/
function &getInstance()
{
static $instance;

if (!isset($instance))
{
$instance=new MYSQL_DB;
}

return $instance;
}

function getConnection() { return $this->dbConn; }
}

[Back to original 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

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