Good people, consider this, and tell me what's right and what's wrong:
<?php
/* mainstream PHP behaviour */
class blah {
private $name;
function __construct($param1, $param2) {
$this->name = $param2."\n";
print($this->name);
}
}
class sonOfBlah extends blah {
function __construct($param) { // overwriting the constructor is allowed
$this->name = $param."\n";
print($this->name); // property read/write is enabled
}
}
/* ext/mysqli behaviour */
class DB extends mysqli {
function __construct() {
/* Need to call parent constructor to even overwrite $host in the
constructor. If
there is a constructor, need to call parent constructor to provide
property access
(internal or external) */
parent::__construct('localhost', 'root', '');
print($this->thread_id)."\n";
}
}
class secondDB extends mysqli {
/* if there is no constructor, all seems well with direct inheritance
(only) */
}
new blah('blah - first param', 'blah - second param');
new sonOfBlah('sonOfBlah - first and only param');
$db = new DB();
$db2 = new secondDB('localhost', 'root', '');
print($db2->thread_id);
?>
Who's right, who's wrong, where are the weaknesses? - Discuss..
- Steph