07-13-2008, 08:25 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
|
My First Class - Any Good?
Hey,
I've never coded using PHP 5's OOP, and while I was planning a new project, I knew I was going to be using it, as well as using the MySQLi function. I've read loads of stuff now on OOP and I think I've got the hang of it, sorta, but at a newbie stage... ya know? lol
I whipped up this code, I just want you to tell me what I did right and wrong and how it can be improved:
PHP Code:
<?php class math {
const host = 'localhost'; const user = 'root'; const pass = 'blergh'; const db = 'project'; public function __construct() { // Start MySQLi connection $mysqli = new mysqli(self::host, self::user, self::pass, self::db); // Check if connect if(mysqli_connect_errno()) { throw new exception('MySQLi did not connect'); } } public function plus($x, $y) { $this->x = $x; $this->y = $y; return $this->x + $this->y; }
}
$class = new math;
try { echo $class->plus(22, 55); } catch(exception $e) { echo $e->getMessage(); }
?>
Cheers!
__________________
Not quite a n00b...
|
|
|
|