Vi säger att vi har denna classen :
Kod:
class DB
{
var $host; // The hostname
var $user; // The username
var $password; // The password
var $database; // The database
function DB($host,$user,$password,$database) // PHP4 class constructor
{
// populate the properties thats needed for connection
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
}
// lite andra metoder
}
nu vill man göra så att PHP 5 kan få använda sin egen construktor syntax och inte använda PHP 5s "backward compability"
då kan man ju göra såhär
Kod:
class DB
{
var $host; // The hostname
var $user; // The username
var $password; // The password
var $database; // The database
function DB($host,$user,$password,$database) // PHP4 class constructor
{
// populate the properties thats needed for connection
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
}
function __construct($host,$user,$password,$database) // PHP5 class constructor
{
{
$this->DB($host,$user,$password,$database);
}
// lite andra metoder
}
eller såhär
Kod:
class DB
{
var $host; // The hostname
var $user; // The username
var $password; // The password
var $database; // The database
function DB($host,$user,$password,$database) // PHP4 class constructor
{
// populate the properties thats needed for connection
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
}
function __construct($host,$user,$password,$database) // PHP5 class constructor
{
// populate the properties thats needed for connection
$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
}
// lite andra metoder
}
Vilket går snabbast av de 2 senare kodstyckerna ?
Och ska man ta med PHP 5s construct och göra så att prestandan sjunker för PHP 4 användarna eller ska PHP 5 användarna få sämre prestanda ( då kör man utan PHP 5s construct