Overloading Class Functions

dDataObjects comes with many class functions. If you'd like to basically use the function, but add to it, it is possible to add additional features by overloading the function.

DO NOT EDIT /path/to/lib/generated/generated_table_name.php - these changes will not be saved if you rerun the program!

To overload a function, edit /path/to/lib/table_name.php (e.g. /path/to/lib/person.php)


<?php

require_once('/path/to/lib/generated/generated_person.php');

class 
person extends generated_person
{
  
/**
  * Retrieves person, if specified by $person_id. Calls global database object
  *
  * @param int $person_id, ID of person to get
  * @global object, $dbh database access object
  * @access protected
  */
  
function person($person_id ''$set_from_query null)
  {
        
$this->generated_person($person_id$set_from_query);
////////////////// All your code below this line ///////////////////////////////

  
}

}
?>



Now redefine the function you'd like to overload, add additional code, and call the parent function


<?php

require_once('/path/to/lib/generated/generated_person.php');

class 
person extends generated_person
{
  
/**
  * Retrieves person, if specified by $person_id. Calls global database object
  *
  * @param int $person_id, ID of person to get
  * @global object, $dbh database access object
  * @access protected
  */
  
function person($person_id ''$set_from_query null)
  {
        
$this->generated_person($person_id$set_from_query);
////////////////// All your code below this line ///////////////////////////////

  
}

  function 
set_name($name)
  {
    if (
$name == 'John Doe')
    {
        return 
false;
    }
    return 
parent::set_name($name);
  }
}
?>