JRegistryFormatPHP/objectToString: Difference between revisions
From Joomla! Documentation
New page: ===Description===
Converts an object into a php class string. NOTE: Only one depth level is supported.
<span class="editsection" style="font-size:76%;">
<nowiki>[</nowiki>[[Descripti... |
m preparing for archive only |
||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 5: | Line 5: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Syntax=== | ===Syntax=== | ||
| Line 19: | Line 19: | ||
!Description | !Description | ||
|- | |- | ||
| | | &$object | ||
| | | | ||
| $object Data Source Object | | $object Data Source Object | ||
| Line 60: | Line 60: | ||
<span class="editsection" style="font-size:76%;"> | <span class="editsection" style="font-size:76%;"> | ||
<nowiki>[< | <nowiki>[<! removed edit link to red link >]</nowiki> | ||
</span> | </span> | ||
<! removed transcluded page call, red link never existed > | |||
===Examples=== | ===Examples=== | ||
=== Code Examples === | |||
<dpl> | <dpl> | ||
noresultsheader=\n | noresultsheader=\n | ||
category=objectToString | category=objectToString | ||
category=JRegistryFormatPHP | category=JRegistryFormatPHP | ||
namespace=CodeExample | |||
category=MethodExample | category=MethodExample | ||
include=* | include=* | ||
format= ,,, | format= ,,, | ||
</dpl> | </dpl> | ||
[[Category:Archived pages API15]] | |||
Latest revision as of 01:04, 25 March 2017
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
Code Examples