Title: Sharing object instance between files
Last modified: August 21, 2016

---

# Sharing object instance between files

 *  Resolved [Cole Slaw](https://wordpress.org/support/users/nthorin/)
 * (@nthorin)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/sharing-object-instance-between-files/)
 * I want to share a object instance between different php files used when creating**
   meta boxes for a custom post type**.
 * **The reason** is that I dont want to to load the same information from every
   included file.
 * From register_post_type i call the following function to create the meta boxes:
 *     ```
       function my_new_meta_box( $post ) {
   
       $video = new MyClass( $post->ID );
   
       # Example meta box
       add_meta_box( 'mbtest1', __( 'XXX', 'abc' ), function() { include( MY_DIR . 'metabox/metabox1.php' ); }, 'mycpt', 'normal', 'default' );
   
       # Example meta box
       add_meta_box( 'mbtest2', __( 'XXX', 'abc' ), function() { include( MY_DIR . 'metabox/metabox2.php' ); }, 'mycpt', 'normal', 'default' );
       }
       ```
   
 * Is there any ‘good’ way to do this, without the use of a global variable?
 * Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [Cole Slaw](https://wordpress.org/support/users/nthorin/)
 * (@nthorin)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/sharing-object-instance-between-files/#post-4226493)
 * In other words I want this to work:
 * [metabox2.php]
    `echo $video->example_property;`
 *  Thread Starter [Cole Slaw](https://wordpress.org/support/users/nthorin/)
 * (@nthorin)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/sharing-object-instance-between-files/#post-4226697)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sharing object instance between files’ is closed to new replies.

## Tags

 * [global](https://wordpress.org/support/topic-tag/global/)
 * [object](https://wordpress.org/support/topic-tag/object/)

 * 2 replies
 * 1 participant
 * Last reply from: [Cole Slaw](https://wordpress.org/support/users/nthorin/)
 * Last activity: [12 years, 7 months ago](https://wordpress.org/support/topic/sharing-object-instance-between-files/#post-4226697)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
