Actions

API15

JRegistryFormatPHP/objectToString

From Joomla! Documentation

< API15:JRegistryFormatPHP
Revision as of 11:39, 25 March 2010 by Doxiki (Talk | contribs)

Replacement filing cabinet.png
This Namespace has been archived - Please Do Not Edit or Create Pages in this namespace. Pages contain information for a Joomla! version which is no longer supported. It exists only as a historical reference, will not be improved and its content may be incomplete.

Contents

Description

Converts an object into a php class string. NOTE: Only one depth level is supported.


[Edit Descripton]

Description:JRegistryFormatPHP/objectToString

Syntax

objectToString(&$object, $params)
Parameter Name Default Value Description
&$object $object Data Source Object
$params $param Parameters used by the formatter

Returns

string Config class formatted string

Defined in

libraries/joomla/registry/format/php.php

Importing

jimport( 'joomla.registry.format.php' );

Source Body

function objectToString( &$object, $params ) {
 
        // Build the object variables string
        $vars = '';
        foreach (get_object_vars( $object ) as $k => $v)
        {
                if (is_scalar($v)) {
                        $vars .= "\tvar $". $k . " = '" . addcslashes($v, '\\\'') . "';\n";
                } elseif (is_array($v)) {
                        $vars .= "\tvar $". $k . " = " . $this->_getArrayString($v) . ";\n";
                }
        }
 
        $str = "<?php\nclass ".$params['class']." {\n";
        $str .= $vars;
        $str .= "}\n?>";
 
        return $str;
}

[Edit See Also] SeeAlso:JRegistryFormatPHP/objectToString

Examples

<CodeExamplesForm />