API15

JRegistryFormatPHP/objectToString: Difference between revisions

From Joomla! Documentation

Doxiki (talk | contribs)
No edit summary
m removing red link to edit, no existant pages
Line 5: Line 5:


<span class="editsection" style="font-size:76%;">
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Description:JRegistryFormatPHP/objectToString|Edit Descripton]]<nowiki>]</nowiki>
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
</span>


{{Description:JRegistryFormatPHP/objectToString}}
<! removed transcluded page call, red link never existed >


===Syntax===
===Syntax===
Line 60: Line 60:


<span class="editsection" style="font-size:76%;">
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[SeeAlso:JRegistryFormatPHP/objectToString|Edit See Also]]<nowiki>]</nowiki>
<nowiki>[<! removed edit link to red link >]</nowiki>
</span>
</span>
{{SeeAlso:JRegistryFormatPHP/objectToString}}
<! removed transcluded page call, red link never existed >


===Examples===
===Examples===
Line 75: Line 75:
  format= ,,,
  format= ,,,
</dpl>
</dpl>
[[Category:Archived pages API15]]

Revision as of 18:44, 12 May 2013

Description

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


[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

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;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

<CodeExamplesForm />