简体   繁体   中英

joomla 1.6 : how $app object print out the entire page contents

I was checking joomla 1.6 index.php and I found the following code at the last line

echo $app;

this prints the entire page contents.

I just printed out the contents in this object using print_r() and I got the following details

JSite Object
(
    [template:JSite:private] => stdClass Object
        (
            [id] => 6
            [home] => 1
            [template] => beez5
            [params] => JRegistry Object
                (
                    [data:protected] => stdClass Object
                        (
                            [wrapperSmall] => 53
                            [wrapperLarge] => 72
                            [logo] => images/sampledata/fruitshop/fruits.gif
                            [sitetitle] => Matuna Market 
                            [sitedescription] => Fruit Shop Sample Site
                            [navposition] => left
                            [html5] => 0
                        )

                )

        )

    [_language_filter:JSite:private] => 
    [_detect_browser:JSite:private] => 
    [_clientId:protected] => 0
    [_messageQueue:protected] => Array
        (
        )

    [_name:protected] => site
    [scope] => 
    [requestTime] => 2011-10-17 17:23
    [startTime] => 1318872200.5365
    [_errors:protected] => Array
        (
        )

)

so how echo $app display all the site contents, it doesn't contains any HTML contents in the object.

Thank you very much

It declares the magic method __toString() in the class.

If this function is declared in a class, the return value of it will be used when the object is casted to a string.

Simple example: http://codepad.org/UmZUQA3v

$app is an object, and print_r accesses its values in different ways from echo . When echo is called, it also implicitly calls the magic __toString method. That has been defined such that it returns a string with the page contents, given the values stored inside of the object. print_r will give you those values, but not the __toString representation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM