Having this problem as well. I tried switching to an earlier version of Rules and it didn't seem to work then either. I tried tracing through the code but it was hard to figure out exactly when it was supposed to pull out the code from the action 'code' field and evaluate it. It seems like it doesn't have an understanding of what the 'code' field is, so it never tries to access that data.

If it helps anyone, a temporary workaround is to use the "Execute custom PHP code action", and just update the field in the node object that should be available (i.e. "The following variables are available and may be used by your PHP code:")

» In "Set a data value", the "Data selector" field should not be required to set/modify a value using PHP evaluation

Component:

Rules Engine

» Rules Core

...just worked through this. It turns out that in the "Set a data value" action, you need to set a value in the 'Data selector' field even if you're planning on completely ignoring it in your PHP code. Leaving the field blank empties the value and ignores all of the PHP code.

The "Set a data value" action should allow the PHP code to return (set) a value even if the "Data selector" field is left empty.

I wasted my 2 days just to understand that "Data selector" field should be provided for using PHP evaluation. I have some complex PHP processing to be performed on field. I also realized a fact that none of the variables are available here in this PHP block. Not even the variables passed to Rules Component. But then I have a workaround. Now I am using "Calculate a value" just prior to "Set a data value". I collect all my data there, do processing and then pass the result as variable. And then I use it directly...

Actually we need a good documentation on Rules, I feel. I have been involved in development of course curriculum of computer institute. So I am confident that I should be able to write a nice walk-through for Drupal Configuration without using PHP. But i dont know where to write this and how.. Can you people please guide me so that this can be a help for new comers..

Confirmed — a data value must be set for the PHP rule to evaluate for an integer data field. Definitely seems like a bug to me…

ETA: That worked on one action I was working on, but now in a new Rule with a new Action that requires a PHP evaluation, I can't get anything to work (assigning a data variable doesn't work, and assigning an initial static value doesn't work, as it's cleared out after I switch to the PHP evaluation. I'm testing with a very very basic declaration just until I can actually get a result to return (e.g. $value = 2; return $value;). Nothing.

Also, I just want to point out that comments #1 & #3 are a bit misleading regarding the specific issue cited by the op. This has nothing to do with accessing variables. The issue is with successfully returning a value to set as a rules variable, and exists whether accessing variables or not (see my example above and the example from the op).

I believe I had to switch back to direct input mode, set an actual value (1), save the form, then come back in and switch to data selector mode, provide a selector, then provide PHP that set $value and returned $value;

bump. Stuck with this with setting a date field. returning a value by php doesn't have any effect. if I add return date('Y-m-d', strtotime('+2 weekdays'));, it is not set. using the selector will give me the value of the selector, not of the outcome of the php code.