Jump to content
php.lv forumi

klase klasē


NaktsSargs

Recommended Posts

  • Replies 33
  • Created
  • Last Reply

Top Posters In This Topic

<?php
class MySQL {
function whatever() {
	 $acl = new ACL();
	 $acl->authorizeMe();
}
}

 

Apmēram šādi? Vai arī - kur īsti ir problēma?

 

No wikipedia:

The Scope Resolution Operator (::) in PHP is officially called Paamayim Nekudotayim (IPA: [paʔamajim nəkudotajim]). It means 'twice colon' or 'double colon' in Hebrew.

Edited by black
Link to comment
Share on other sites

saakumaa uztaisi mysql klases obektu, ko padod jaunajai klasei kaa parametru vai global variablu.

var arii jaunajai klasei mysql noraaditi kaa extends, bet tad vinjsh taisiis vairaakas konekcijas.

Link to comment
Share on other sites

Nu, vispār jau gadījumā ar db klasi ir jāpielieto singletone paterns. Un atrisinās visas problēmas :)

class MysqlClass {
private static $instance = NULL;

static function instance() {
	// paarbaudam, vai ir izveidots klases eksemplaars
	if(empty(self::$instance)) {
		// ja nav, izveidojam
		self::$instance = new MysqlClass();
	}
	return self::$instance;
}
private function __construct() {
	// te konecteejamies ar db
}
}
//--------------------
class Authenticate {
function whatever() {
	 $db = MysqlClass::instance();
	 // te daram visu, ko vajag ar db klassi
}
}

Edited by john.brown
Link to comment
Share on other sites


×
×
  • Create New...