I'm getting the error:

Notice: Undefined offset: 0 in __lambda_func() (line 2 of /drupal/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function).

This only happens the second time the node is loaded (and all subsequent times) after the view has been re-saved, if that helps.

Also, the solution provided for this issue: http://drupal.org/node/1223184 also works here, so it's probably part of the same bug. Even though the bug occurs, the values returned are correct and everything works as intended.


Status:Active» Fixed

you should check if the variable is filled upfront, using isset() :

return $data->field_field_exp_thumbvideo[0]['rendered']['#markup'];
else {
return 'no video';

see also #1264630: What would be the correct code to test the value of a field ?

Status:Fixed» Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

This behavior is still present in the current version.

Some explaining in the description would be helpful. Now it only mentions $row-> but this doesn't really work, so how are people supposed to know the way to handle $data-> when using your module?

P3t3r, I would consider this module broken, #1140896: Variable $row does not contain correct values ($data->_field_data does) suggests workarounds.

The module may be broken, but I'm not aware of any other modules offering such functionality.
I got here from this topic which discusses a problem very similar to mine. Do you know any other modules that could make this work?

PS: this is the exact thing I want to do if it matters. Just like the other topic I see no way to do it without this module. It are both very standard things to do and yet it needs a module which has open bugs of over a year old. :(

Priority:Minor» Major
Status:Closed (fixed)» Active

This bug is still alive and well.

The funny thing about it is that I get a result - all the results I want! It just happens to add this error when I render outside of the Views preview. Even in spite of that, I still have all the data I need.

Setting the priority and status fields accordingly.

The solution proposed in #1 is very close to the right solution here. One of my fields was blank in some posts so it continued to be an issue...

Looking at that example code in #1:

return $data->field_field_exp_thumbvideo[0]['rendered']['#markup'];
else {
return 'no video';

I would change the first line to identify only if the delta exists:

return $data->field_field_exp_thumbvideo[0]['rendered']['#markup'];
else {
return 'no video';

Using this method it is not necessary to (re)entity_load or (re)node_load as suggested in #1140896: Variable $row does not contain correct values ($data->_field_data does). The thought of doing that would give me code nightmares.

Marking #1496586: Sort error as a duplicate of this tread.

I got:
Notice: Undefined variable: output in __lambda_func() (line 34 of /DRUPAL7/sites/all/modules/contrib/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function).

Notice: Undefined property: stdClass::$taxonomy_vocabulary_vid in __lambda_func() (line 8 of /DRUPAL7/sites/all/modules/contrib/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function).

Using 7.x-1.x-dev (2012-Feb-21) & Views 7.x-3.5.

#1 work for me.

I am getting this error as well, and #1 is not working for me.

Notice: Undefined offset: 0 in __lambda_func() (line 5 of /sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function).

It occurs because one of my fields, field_description, is optional and sometimes has no value. I attempted to use if, if/else, if(isset), !empty, etc. in order to hide "empty" fields and remove the error message. The view displays exactly how I need, but the error is always there.

Is there a fix to this problem?

After doing a lot of trial and error, I finally decided to scrap what I was trying to accomplish using Views PHP. Instead I ended up just trimming the default field (under Rewrite results). Not exactly the desired effect, but it does not return that error and since we're working against a deadline, it will have to do for now. I'll keep following this issue thread though, should a solution be proposed.

@jacquelynfisher, can you post the offending lines?

I was having the same issue. Adding the isset only partially worked. For whatever reason even though it wasn't set it went through once so I had to add a second trap.

If (isset($data->field_field_event_tags[0]['rendered']['#markup'])) { //I ADDED THIS LINE FIRST
$tagcnt = count($data->field_field_event_tags);

for($i = 0; $i <= $tagcnt; $i++) {

If (isset($data->field_field_event_tags[$i]['rendered']['#markup'])) { //THEN ADDED THIS LINE
$stag = $data->field_field_event_tags[$i]['rendered']['#markup'];

Adding the isset before each of the call to the markup fixed my issue, not exactly sure why it blew through the first isset though.

I ran into this as well. I have fields with data that are giving me an error message, even though the data is being pulled. (How is that possible?) I have to abandon views altogether for this project because of the bug.

Using the "isset" function to check if a field is not set was enough to get me past this bug. You may have to do it for each field being rendered via PHP.

For me, the fields were set, with data, but I still received an error. (The data was still included in the reslults, but the error message made the page useless.)

I have the results correctly displayed but always this error... How can we get rid of it?

looks more infomation is needed to reproduce this inssue, then we can fix it.

May you advise the way to product this problem?

My fault: made a mistake in my code that led me to this thread; everything works fine now! Sorry