# XoopsObject

## Definition

**XoopsObject** is an Abstract class, a base class for all objects in the Xoops kernel (and beyond)

![](/files/-M5aqYwKVhpcf3UiCMZM)

## Usage

XoopsObject should be handled as an abstract class and has the following useful functions:

* **initVar($key,$data\_type,$value,$required,$maxlength,$options)** :  initialize a variable. Use this, when extending XoopsObject instead of declaring variables the normal way. for $data\_type, see below. $options is string for select options   &#x20;
* **getVar($key,$format)** - retrieves an object variable ($format is 's' for display on page, 'f' for form info, or 'n' for no cleaning.
* **getVars()** - retrieves array of key=>value pairs
* **cleanVars()** - "cleans" the object variables, which have changed, according to their type set in initVar()
* **clone()** - create a clone(copy) of the current object
* **setVar($key,$value,$not\_gpc)** - assign a value $value to a variable $key; sets object dirty
* **setVars($var\_array)** - assign values to variables from a key=>value pair array; sets object dirty
* **assignVar($key,$value)** - assign a value to a variable
* **assignVars($var\_array)** - assign values to variables from a key => value pair array

The last two functions are for new(-ly instantiated) objects. For existing objects, which are subsequently modified, you should use setVar() and setVars() - this will set the object status to "dirty" i.e. that it has been modified and variable values not sanitized.

Data Types (for initVar function above):

* XOBJ\_DTYPE\_TXTBOX - Text Box
* XOBJ\_DTYPE\_TXTAREA - Text Area
* XOBJ\_DTYPE\_INT - Integer
* XOBJ\_DTYPE\_URL - URLs
* XOBJ\_DTYPE\_EMAIL - E-mails
* XOBJ\_DTYPE\_ARRAY - Arrays
* XOBJ\_DTYPE\_OTHER - Others (won't be cleaned)
* XOBJ\_DTYPE\_SOURCE -
* XOBJ\_DTYPE\_STIME - Short Time
* XOBJ\_DTYPE\_MTIME - Medium Time
* XOBJ\_DTYPE\_LTIME - Long Time\*\*

Note Don't give, to a field's name of your table, the table's name or you will have a problem in the XoopsObject class while saving the datas


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xoops.gitbook.io/xoops-modules-cookbook/core-classes/core/xoopsobject.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
