How to resolve the "undefined variable" notce when I put a flag on a Views page? I want to place a flag link on a page, as suggested on that page: https://www.drupal.org/node/295383

The flag will subscribe the user to the most recent content page, which is done in Views.

I have the Flags: subscribe (by current user) Relationship.

I have installed Views PHP and I want to add to the header of the view a Global:PHP with the code &lt;?php print flag_create_link('subscribe', $node-&gt;nid); ?&gt;

Unfortunately I receive an error:


  Notice: Undefined variable: node in __lambda_func() (line 1 of .../sites/all/modules/views_php/plugins/views/views_php_handler_area.inc(39) : runtime-created function).
  Notice: Trying to get property of non-object in __lambda_func() (line 1 of .../sites/all/modules/views_php/plugins/views/views_php_handler_area.inc(39) : runtime-created function).


What could be the reason for that?

Any help appreciated.
The error arises because there is no $node variable defined in the scope.
Try looking inside the $results variable; something like this should work:

&lt;?php print flag_create_link('subscribe', $results[0]-&gt;nid); ?&gt;


This will print a subscribe link for the first row of the view. 
Also, you have to ensure that the nid is present in your result object. It should be already there, but if not, add the "Content: Nid" field and hide it by checking the "Exclude from display" option.