phalcon控制器中setVar和Magic setter之间的区别是什么

Reading the documentation of phalcon https://docs.phalconphp.com/en/3.0.0/reference/views.html I found that it's possible to pass variables from the controller to the view in 2 different ways:

  1. Using setVar()

    $this->view->setVar("username", $user->username);
    $this->view->setVar("posts",    $posts;
    
  2. Using the magic setter

    $this->view->username = $user->username;
    $this->view->posts    = $posts;
    

What's the difference between the two and what is the magic setter really, I couldn't find what it is.

Only difference is return value.

Method setVar return $this, magic setter return void.

Check this: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/view.zep#L1373 and compare with this: https://github.com/phalcon/cphalcon/blob/master/phalcon/mvc/view.zep#L450

The difference is performance. Better to use setVar method. Of course in real world the difference will be none with setting two variables.