Last reviewed: 18 Nov 2005, Joomla 1.0.3


Copy the contents of an object into an array.

This function traverses each variable in an object and stores it in an array. Objects contained in objects are also converted into an array.

Returns an array containing all the variables in the object if successful. If the parameter passed to it is not an object, it will return null.


array mosObjectToArray ( object $obj )

is the object to be converted to an array.

Defined in

(includes/joomla.php prior to Joomla 1.1)
(includes/mambo.php prior to Joomla 1.0)


Example: This function displays the contents of an object as an array.

class exampleA {
    var $red;
    var $orange;
    var $yellow;
class exampleB {
    var $green;
    var $blue;
    var $violet;
    function exampleB() {
        $this->green = 5;
        $this->blue = 7;
        $this->violet = array('a', 'b', 'c');
function displayObject() {
    $obj1 = new ExampleA();
    $obj1->red = 5;
    $obj1->orange = new ExampleB();
    $obj1->yellow = "OK";
    $array1 = mosObjectToArray( $obj1 );
    foreach ($array1 as $k => $v) {
        echo "$k => $v <br />";

might produce:

red => 5
orange => Array
yellow => OK 

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Tuesday, 03 January 2006 )