Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8880309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:08:36+00:00 2026-06-14T20:08:36+00:00

I have a function within my module: <?php function foo($node) { module_load_include(‘php’, ‘mymodule’, ‘path/to/filename’);

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T20:08:37+00:00Added an answer on June 14, 2026 at 8:08 pm

    No, there is no way to do this using module_load_include(). From php.net:

    If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function.

    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:

    1. Add a function your include file, then call that function inside your foo() function after using module_load_include().
    2. Use a regular PHP include instead of 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In PHP, is it possible to have a function within a class that's non-static,
Possible Duplicate: How to use include within a function? i have two file inc.php
I have a PHP function in a Drupal 6 .module file. I am attempting
I'm working with node and would like to include a module stored on a
I would like to register a custom utility / module within YUI3 that is
I have a background worker which calls a function within a separate class. This
The problem seems very strange. I have a AJAX helper function within a same
I have a function definition of the following form (within a large code): class
Background I have a function that takes a config object as an argument. Within
I have the following function which works very well within a $(document).ready(function(){ $('.threadWrapper >

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.