Closed (fixed)
Project:
Views PHP Filter
Version:
5.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
19 Nov 2007 at 23:37 UTC
Updated:
31 May 2009 at 18:18 UTC
Here's the error I am getting.
My PHP snippet output is: Array ( [0] => 1 [1] => 119 ) as per instruction given for the output. And here's the last rows of the code:
............
$sql = db_query("SELECT n.nid FROM {nat} n WHERE $sql_string");
while($row = db_fetch_array($sql)) {
$prod_nid[] = $row['nid'];
}
return $prod_nid;
Fatal error: Call to a member function add_where() on a non-object in /var/usr/local/apache2/htdocs/aacc/sites/all/modules/viewsphpfilter/viewsphpfilter.module on line 79
Comments
Comment #1
ivrh commentedAfter tweaking around found what caused this error.
In my PHP snipped I used $query = db_query(...); which didn't talk properly to $query object by reference. Simple renaming $query into $myquery solved the issue straight away.
Comment #2
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #3
Morgenstern commentedI got the same error and I was totally confused until I finally found this issue.
The best way to solve this issue would be to have the module check if there's a variable $query used in the PHP-Snippet and automatically renaming it. Unfortunately my knowledge of PHP is too poor to do that.
An alternative method of dealing with this issue might be leaving a hint that users shouldnt use $query in their PHP code in the UI.
Comment #4
lamojo commentedok, i would not be surprised if a lot of people run into this problem, as soon as the database gets involved, and they use their intuition to name the variable name for a query: $query...
Comment #5
gnassar commentedThe module's purpose is to inject Drupal-enabled PHP into the view. It by necessity, therefore, presupposes a level both of PHP knowledge and Drupal knowledge. I recognize that many folks wanting to use this module will not have as much of the latter as the former. But access to the available Drupal objects, including $query, is part of its intent, for those with the guts to mess with that sort of thing. If it were the only variable name in use, I'd consider making a warning if it's seen in the code. But this will basically be the case for any object currently "live" when the view executes, and I can't cover every case.
I think this is a good thing to put in the README, as a heads-up to those not so savvy with Drupal's guts, but it's a won't-fix as far as the code goes unless someone can convince me otherwise.
Comment #6
gnassar commentedForgot to change the title.
Comment #7
gnassar commentedAdded to readme.