PDA

View Full Version : PHP Simple OOP problem; why won't this work?!



Sage_of_Fire
September 10th, 2008, 06:47 PM
I'm trying to abstract one of my php scripts into a class, and I keep getting nonsense errors. I have experience in AS3 OOP, but this is so simple yet so broken. Here's the class:


<?php

class DBModel {

private $dbc;
private $table;

public function __construct($new_dbc, $new_table) {
$this->$dbc = "something";
echo "Made DBModel:" . $new_dbc . $new_table;
}
}

?>

... and the script that instantiates it:


<?php

require_once ('classes/dbmodel.php');

$db_model = new DBModel('string','Number');

unset($dbc);

?>

... and the error.


Fatal error: Cannot access empty property in /home2/appalac7/public_html/classes/dbmodel.php on line 9

I'm running php 5.2, so I know it's not version problems. Thanks.

hl
September 10th, 2008, 07:06 PM
Try $this->dbc instead of $this->$dbc

Sage_of_Fire
September 10th, 2008, 08:12 PM
Yep, your solution works. That's just the sort of syntax mistake I make all the time. Thanks. *bangs head on desk*