[support] class and globals in functions (maybe PHP)

Ivan Sergio Borgonovo mail at webthatworks.it
Tue Oct 2 13:41:00 UTC 2007


I've to access an external DB (MS SQL so it is too complicated to
rewrite the DB layer... bla bla)

So I plugged in my class to be seen inside hooks...


//catalog_base.inc
$param="salve";

class Catalog_DB {
  function __construct($DBParam) {
//...
  }
  public function test() {
  print("<!-- ciao ciao -->");
 }
}

$DBGorilla=new Catalog_DB($param);

//catalog.module
$path = drupal_get_path('module', 'catalog');
require_once($path . '/catalog_base.inc');

//... hooks etc...


//test1
$DBGorilla->test();



function catalog_asearch() {
  global $DBGorilla;
  //test2
  $DBGorilla->test();
  $query=$DBGorilla->test();
  return "";
}

test1 succeed
test2 fail with Call to a member function test() on a non-object
in ...

using $GLOBALS makes no difference...
but drupal code is plenty of

global $user;

in functions

what's wrong?

thx

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it



More information about the support mailing list