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

ivrh’s picture

Status: Active » Fixed

After 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.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

Morgenstern’s picture

Component: Code » User interface
Status: Closed (fixed) » Active

I 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.

lamojo’s picture

ok, 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...

gnassar’s picture

Component: User interface » Documentation
Category: bug » feature

The 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.

gnassar’s picture

Title: Fatal error: Call to a member function add_where() on a non-object » Mention possible conflicts in user code with Drupal/Views objects in readme

Forgot to change the title.

gnassar’s picture

Status: Active » Closed (fixed)

Added to readme.