I added a views_php field to my view
I get the following with the offset incremented for each row ie. Undefined offset: 1, 2, 3 depending on the row
Notice: Undefined offset: 0 in views_php_handler_field->render() (line 218 of modules/all/views_php/plugins/views/views_php_handler_field.inc).
Warning: Invalid argument supplied for foreach() in views_php_handler_field->render() (line 218 of modules/all/views_php/plugins/views/views_php_handler_field.inc).
I think it is an off by 1 error.
$this->view->row_index returns 1 for the first row
but $this->view->style_plugin->rendered_fields[1] is not defined instead $this->view->style_plugin->rendered_fields[0] is.
function render($values) {
// Execute output PHP code.
if (!empty($this->options['php_output']) && isset($this->php_output_lamda_function)) {
$normalized_row = new stdClass;
foreach ($this->view->style_plugin->rendered_fields{$this->view->row_index} as $field => $value) { <----- offending line 218
$normalized_row->$field = $value;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | views_php_handler_field_20151003.patch | 806 bytes | kotoponus |
| #5 | views_php_error_debug.png | 50.79 KB | kotoponus |
| #4 | order-01.jpg | 8.79 KB | ajlow |
| #4 | order-00.jpg | 8.72 KB | ajlow |
Comments
Comment #1
VenDG commentedI am also getting the same error.
Comment #2
kenheim commentedDid you find a solution? My php code is functioning fine - outputting what I want, but these error messages are of some concern.
Comment #3
ajlow commented*bump* I am too...
Comment #4
ajlow commentedDoing some investigation and I found something interesting.
If I had my php field as the first field in the list of fields, I get the error:
If, however I moved the php field down the list of fields, it is ok:
It is strange but it seems to work for me...
Comment #5
kotoponus commentedSocialNicheGuru's description spot on.
In order to see the values of the variables in focus here in line 218, I have done the following:
You see:
It is clear that the $this->view->row_index is supplying 1 when there is no index 1 in $this->view->style_plugin->rendered_fields. So, if you force feed the index (at 3rd debug), it is spitting the value hence no error message to be produced.
So, my first guess is either the index should be returning 0 instead of 1 as SocialNicheGuru says or $this->view->style_plugin->rendered_fields to contain an additional value for index 1. Considering this particular value set should appear as a first row in this particular view, index 0 seems correct. In which case, the index should be fetching 0 rather than 1?
Comment #6
kotoponus commentedOk, the thing is, it does return the result I want. It just returns the error message for me as well.
Looking at the behaviour, $this->view->style_plugin->rendered_fields acts like an accumulator of all the rows to go through. So, "CSR" comes first for me and the second row value "ABC" comes next. I see the error at the point of processing "ABC" row, therefore, I only see CSR at index 0 in $this->view->style_plugin->rendered_fields. And this makes sense from the comment from SocialNicheGuru:
This means we will never enter this foreach loop. But the codes further down produces the final product $value for "ABC" which is an rendered HTML for ABC.
Maybe there is a case when we will actually see the routine enters foreach loop, but, at this point, I say the loop routine should be ignored if $this->view->style_plugin->rendered_fields{$this->view->row_index} is not set.
Like,
Or something more elegant if anyone can come up with it.
What do you view_php maintainers think?
Comment #7
kotoponus commentedComment #8
kotoponus commentedComment #9
ismail cherri commentedHi,
The patch in #6 fixes the issue.
In order to reproduce the error, the PHP field needs to be the first field; you can also fix the error without patching by placing the PHP field a second or more.
Comment #10
joelpittetI tested #6 and it works as described in #9
I wonder why
row_indexis 0 when the PHP field is second position yet, starting at 1 when it's in the first position.Comment #11
jrochate commentedSo many years later, it's still valid :)
Thanks for sharing.