Calling a PHP class variable with a variable
<p>I have a PHP class definition that uses a class called databaseObject for all typical database methods (Crud, Etc). I recently changed my database structure so that the id columns in each table are no longer called "id" and are now whatever the table holds + id (For example: Companies Table has an id of "companyId"). So now in my classes that extend databaseObject I include a static variable called $table_id that holds the name of the id for that table. I have run into a situation when now I need to call for that class variable. Example code is below. This code is being run in PHP 5.3.  </p>

<pre><code>//databaseObject Delete Method;
public function delete() {
    global $database;
    //DELETE FROM table WHERE condition LIMIT 1
    //escape all values to prevent SQL injection
    // - use LIMIT 1
    $sql  = "DELETE FROM ".static::$table_name;
    $sql .= " WHERE ".static::$table_id."=". $database-&gt;escape_value($this-&gt;id);
    $sql .= " LIMIT 1"; 
    $database-&gt;query($sql);
    return ($database-&gt;affected_rows() ==1) ? true : false;
}

//Actual Class that creates the issue
require_once(LIB_PATH.DS.'database.php');
require_once(LIB_PATH.DS.'databaseobject.php');

class Contact extends DatabaseObject {
    protected static $table_name="contacts";
    protected static $table_id="contactId";
    protected static $db_fields = array('contactId','companyId','contactName', 'phone', 'fax', 'email');
    public $contactId;
    public $companyId;
    public $contactName;
    public $phone;
    public $fax;
    public $email;
}

//Code that calls the method
$contact = Contact::find_by_id($_GET['contactId']);
if($contact &amp;&amp; $contact-&gt;delete()) {
    $session-&gt;message("The Contact was deleted.");
    log_action('Contact Deleted', "Contact was deleted by User ID {$session-&gt;id}");
    redirect_to("../companies/viewCompany.php?companyId={$contact-&gt;companyId}");    
} else {
    $session-&gt;message("The Contact could not be deleted");
    redirect_to('../companies/listCompanies.php');
</code></pre>

<p>}</p>
