A
A
Alexander2019-12-15 18:17:13
PHP
Alexander, 2019-12-15 18:17:13

What is Undefined offset?

Versions: php - 7.3, sim - 5.0
There is AclSubscriber, a subscription to CONTROLLER. The check function is called first.

Here she is

public function check(ControllerEvent $event): void
    {

        $request = $event->getRequest();

        if($request->headers->has('authorization')){
            /** @var AccessTokenInterface $token */
            $token = $this->container->get(AccessTokenInterface::class);
        }else{
            $token = null;
        }



        $acl = new AclPrivileges($token, $this->rules);
        $a = (array) $event->getController();
        $s = $a[1];

        var_dump($s);

        list($controller, $action) = [get_class($event->getController()), $s];

        $resource = "{$controller}@{$action}";


        $acl->isAllowed($resource);

        return;
    }


The most remarkable thing is this: It gives a notice on the line $s = $a[1];, namely on $a[1], as you can see, the result is written to the variable $s, but when the variable is wardumped, the contents of this variable are displayed (the same as for $a[1]), so this is the story:
5df64dbb1d7cb771932232.png
That is, by index in the array there is a value "login", but PHP considers that such an index does not exist. How can this be?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2019-12-15
@AleksandrB

Everything is dumping fine for you - if you see, there is the word login on the screen at the top.
Obviously, the code works again, where there is no method and crashes, because this data is not available again ...
To find out, before receiving $s , do:
And show complete output of ALL values ​​...
In general, take the time and put xDebug, you would understand within 2 seconds what and where it arrives and why ...
If you chose debug as before on your knee, then the symphony has a dump () function, all calls which are displayed in the developer panel!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question