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

  • SEARCH
  • Home
  • 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 6113693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:53:18+00:00 2026-05-23T14:53:18+00:00

Is my use of @global correct in the following case? // File: my_special_class.php <?php

  • 0

Is my use of @global correct in the following case?

// File: my_special_class.php
<?php
...
class MySpecialClass {

    function display_template() {
        // Following variable will be available from context of 'template.php':
        $instance = array( 'title' => 'Test Page' );

        include('template.php');
    }

}

// File: template.php
<?php
/**
 * Template for ...
 *
 * @copyright Me
 * @version 1
 *
 * @global array $instance Template instance parameters.
 */
?>
<h1><?php echo $instance['title']; ?></h1>

Is there a standard way of documenting this?

It is primarily a reminder for those reading the code, but it would be useful if this information was also present under phpDocumentor generated documentation.

  • 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-05-23T14:53:19+00:00Added an answer on May 23, 2026 at 2:53 pm

    Actually, your $instance variable is not in the global scope, based on this code… it is local to the MySpecialClass::display_template() function only.

    If you want to highlight, from the template.php documentation page, that there is something of significance to the reader with regard to the $instance variable, you could use the @see tag in template.php’s file-level docblock (the location that you currently have the @global tag) to point the reader to the MySpecialClass’s function that sets $instance:

    <?php
    /**
     * Template for ...
     *
     * @copyright Me
     * @version 1
     *
     * @see MySpecialClass::display_template() to see how $instance is populated
     */
    ?>
    <h1><?php echo $instance['title']; ?></h1>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Global scope allows you to use a variable in a function that was defined
i declare a global variable and use and modify its value in the function.
I'm trying to use usort() and leverage a global variable inside its function scope,
Example : Say I have a logging class, and I use a global variable
I use global variable $table_prefix to differ whether I work on Word Press or
I have set an array in my config file that I use global in
Somebody said that when your PHP code and application use global variables then it
As I know, I can use global variable transfer the value among the multi
Due to a wave of criticism to use Global Vars in my Java post
Do you use a global, catchall namespace for all of your extension methods, or

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.