Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comments
Comment #1
johnvyou should check if the variable is filled upfront, using isset() :
if(isset($data->field_field_exp_thumbvideo[0]['rendered']['#markup'])){
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 ?
Comment #3
P3t3r CreditAttribution: P3t3r commentedThis 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?
Comment #4
johnvP3t3r, I would consider this module broken, #1140896: Variable $row does not contain correct values ($data->_field_data does) suggests workarounds.
Comment #5
P3t3r CreditAttribution: P3t3r commentedThe 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. :(
Comment #6
Anonymous (not verified) CreditAttribution: Anonymous commentedThis 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.
Comment #7
Anonymous (not verified) CreditAttribution: Anonymous commentedThe 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:
I would change the first line to identify only if the delta exists:
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.
Comment #8
mgiffordMarking #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.
Comment #9
truyenle CreditAttribution: truyenle commented#1 work for me.
Comment #10
jacquelynfisher CreditAttribution: jacquelynfisher commentedI am getting this error as well, and #1 is not working for me.
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?
Comment #11
jacquelynfisher CreditAttribution: jacquelynfisher commentedAfter 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.
Comment #12
johnv@jacquelynfisher, can you post the offending lines?
Comment #13
Linked25 CreditAttribution: Linked25 commentedI 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.
Comment #14
kennyacock CreditAttribution: kennyacock commentedI 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.
Comment #15
modctek CreditAttribution: modctek commentedUsing 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.
Comment #16
kennyacock CreditAttribution: kennyacock commentedFor 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.)
Comment #17
sacha05 CreditAttribution: sacha05 commentedI have the results correctly displayed but always this error... How can we get rid of it?
Comment #18
zterry95 CreditAttribution: zterry95 commentedlooks more infomation is needed to reproduce this inssue, then we can fix it.
May you advise the way to product this problem?
Comment #19
sacha05 CreditAttribution: sacha05 commentedMy fault: made a mistake in my code that led me to this thread; everything works fine now! Sorry
Comment #20
priyankprajapati CreditAttribution: priyankprajapati commentedwhen i write this cod in global php filed then error will display like this.
Notice : Undefined index: 0 in __lambda_func() (line 5 of /var/www/html/java/drupal_fb/sites/all/modules/views_php/plugins/views/views_php_handler_field.inc(202) : runtime-created function)
how can i solve this error ???
Comment #21
fizk CreditAttribution: fizk commentedPlease reopen if this is still an issue with steps to reproduce.