->set*() and ->get*()

->set*() and ->get*() – Automatic Setters and Getters using overload


true | string $DB_DataObject->set* ( mixed $value )

mixed $DB_DataObject->get* ( )


From version PHP 4.3.2RC2 onwards, DB_DataObject is automatically overloaded, providing access to all variables using $object->set{ColumnName}() and $object->set{ColumnName}($value) even if you have not defined the method.

It is assumed that set methods return strings as errors or TRUE, so that it can interact with setFrom and return array's of error strings.

The get Methods are used by toArray(), if defined they can be used to alter the appearance of columns ,like making dates human readable

The logic is very simple, if you call $object->setXXX() and it is not defined, it will just set the value, if you define a method setXXXX, that will be called instead of the default handler, same applies to getXXX().

Due to the naming conflict possiblity of a column named from, the associated method for column 'from' is set_from, rather than setFrom()


  • mixed $value - on setters only (the value to assign to the column), on getters you may like to implement date formating or sprintf formating as the argument.

Return value

mixed - setters will return TRUE from the default method, in your implementations of setters. It is expected that setXXX($value) will return a string (the error) if it is invalid or TRUE on success. getXXX may return the value or a formated value, remember though it affects $object->toArray().


This function can not be called statically.

Warning: This is experimental, its behavour may change slightly in the future.


Simple find and fetch of data based on Object Vars

class DataObjects_Person extends DB_DataObject {

// you can define this method after you implement a call to it!
    // as it is automatically implemented to return $this->date_of_birth by 
    // the overload __call() method.
function getDate_of_Birth() {
date('d M Y'strtotime($this->date_of_birth));
$person = new DataObjects_Person;


// now lets use the getters and setters even though some are not defined.
echo $person->getName() . ' was born on  ' $person->getDate_of_Birth();

Resulting Output

       Fred Blogs was born on 1 April 1970
add another dataobject to build a create join query (Previous) Copy items from Array or Object (for form posting) (Next)
Last updated: Fri, 24 Mar 2017 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.