I have a function within my module:
<?php
function foo($node) {
module_load_include('php', 'mymodule', 'path/to/filename');
}
?>
in filename.php i would like to be able to access the $node variable, or any other.
<?php
var_dump($node);
?>
how can i achieve that resp. how do you do this?
No, there is no way to do this using
module_load_include(). From php.net:Since the include happens inside
module_load_include(), the include file will contain all variables that are in the scope of that function, not your function.You can either:
foo()function after usingmodule_load_include().module_load_include():include DRUPAL_ROOT . '/' . drupal_get_path('module', 'mymodule') . '/path/to/filename.php';Also, a word of advice: it is generally a bad idea to not wrap functionality in functions. When you use functions, you get better variable scoping, fewer unintentional side effects, and better code reusability. So, I would suggest you choose the first option.