0
votes

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?

2
request is a property of $request - u_mulder
look inside the request method, it's poor coding to use a variable name $request when you have a method inside with the same name. - Forbs

2 Answers

3
votes

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()

1
votes

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