Undefined variable: nid I put this code in Rules Action PHP Evaluation. What I want is getting the field_price's value, changing it for negative and returning it for Rule. With this I will be able to charge points because in Rules (Drupal 7) it is impossible to put "-" before data-selector (in this case, field_price's value) and make it negative to charge these points instead of adding them. 

&lt;?php
if (arg(0) == 'node') {
   $nid = arg(1);
}
   $node = node_load($nid);
   $value = $node-&gt;field_price['und'][0]['value'];
   return $value;
?&gt;
The reason you're getting the error "Undefined variable: nid" in some cases is obvious. You're only assigning a value to $nid if the following is TRUE: arg(0) == 'node'. If arg(0) is something else, $nid never becomes defined, causing the error.

Since it doesn't make sense to use $nid unless it is defined, you can get rid of error by moving the construct where you use the value of $nid inside the if-test, like this:

&lt;?php
if (arg(0) == 'node') {
  $nid = arg(1);
  $node = node_load($nid);
  $value = $node-&gt;field_price['und'][0]['value'];
  return $value;
}
else {
  return FALSE;
}
?&gt;


Note that this will return the value stored in the field field_price if arg(0) is equal to the string 'node', and return FALSE otherwise.

You write:


  What I want is getting the field_price's value, changing it for negative and returning it for Rule.


Please note that your original code does not do that.  Nor does mine.  I just told you how to fix the bug. The business logic is still up to you.

Please also note that this has nothing to do with Drupal - it is Programming 101.