Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define( 'DATA_BASE', 'db_name' );
- define( 'USER_NAME', 'user_name' );
- define( 'PASSWORD' , 'password' );
- define( 'HOST' , 'localhost' );
- class MysqliDB
- {
- private $user;
- private $password;
- private $database;
- private $host;
- public function __construct( $user, $password, $database, $host = 'localhost' )
- {
- $this->user = $user;
- $this->password = $password;
- $this->database = $database;
- $this->host = $host;
- }
- public function __construct()
- {
- $this->user = USER_NAME;
- $this->password = PASSWORD;
- $this->database = DATA_BASE;
- $this->host = HOST;
- }
- }
- class MysqliDB {
- public function __construct( $user = USER_NAME, $password = PASSWORD, $database = DATA_BASE, $host = HOST ) {}
- }
- new MysqliDB( null, 1234 );
- public function __construct( $user = USER_NAME, $password = PASSWORD, $database = DATA_BASE, $host = HOST )
- {
- $this->user = $user;
- $this->password = $password;
- $this->database = $database;
- $this->host = $host;
- $this -> checkIntegrity();
- }
- public function checkIntegrity()
- {
- if( empty( $this -> username ) ) {
- die( 'Usuário MySQL ausente' );
- }
- }
- }
- class MysqliDB {
- public function __construct()
- {
- list( $user, $password, $database, $host ) = func_get_args();
- $this->user = $user;
- $this->password = $password;
- $this->database = $database;
- $this->host = $host;
- }
- }
- list( $user, $password, $database, $host ) = func_get_args() + array( USER_NAME, PASSWORD, DATA_BASE, HOST );
- class Foo {
- function Foo() {
- // No PHP4 esse método era o construtor
- }
- }
- class Foo {
- function Foo() {
- echo __METHOD__, '<br />';
- }
- public function __construct() {
- echo __METHOD__, '<br />';
- }
- }
Add Comment
Please, Sign In to add comment