简体   繁体   中英

PHP Class object syntax that I don't understand

I've inherited a Symfony app and have come across some syntax I've not encountered before:

$data = $request->request->all();

The $request is a HttpFoundation request object. There is no all() method in the class. The result of the statement is an array w/ all the fields from a submitted form.

So how do I read the the statement? What does the "->request->" mean?

http://api.symfony.com/3.1/Symfony/Component/HttpFoundation/Request.html

there is a $request property in that object which is the instance of ParameterBag which has all()

Consider the following as an example:

<?php

class Foo
{
    public $bar;

    public function __construct()
    {
        $this->bar = new Bar;
    }    
} 

class Bar
{
    public function greet()
    {
        return 'hello earth';
    }
}

$foo = new Foo;
echo $foo->bar->greet();

Output:

hello earth

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