Title: Instantiate PHP class in header,.php use elsewhere
Last modified: August 21, 2016

---

# Instantiate PHP class in header,.php use elsewhere

 *  Resolved [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [13 years ago](https://wordpress.org/support/topic/instantiate-php-class-in-headerphp-use-elsewhere/)
 * I’m not even sure what search terms might lead to an answer to this question 
   so I’ll just ask.
 * I want to include, and declare a PHP class in header.php. Then I’d like to use
   that class in other files like page.php or content-page.php.
 * I include and instantiate a class in header.php, then I attempt to use it in 
   content-page.php but I get an error indicating that my object is not defined.
   Specifically “call to a member function on a non-object”
 * I also tried just declaring a variable in header.php and then using it elsewhere.
   Same problem. The variable is undefined.
 * I figured it had something to do with scope. In case content-page.php is actually
   within a function scope, I included a “global” statement just before I attempted
   to use the object. That doesn’t help.
 * Is this problem to be expected and is there some way around it?

Viewing 1 replies (of 1 total)

 *  Thread Starter [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * (@batman42ca)
 * [13 years ago](https://wordpress.org/support/topic/instantiate-php-class-in-headerphp-use-elsewhere/#post-3783649)
 * Never mind. I just figured it out. I need to declare my object as global not 
   just where I use it but also where I instantiated it in header.php

Viewing 1 replies (of 1 total)

The topic ‘Instantiate PHP class in header,.php use elsewhere’ is closed to new 
replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [batman42ca](https://wordpress.org/support/users/batman42ca/)
 * Last activity: [13 years ago](https://wordpress.org/support/topic/instantiate-php-class-in-headerphp-use-elsewhere/#post-3783649)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
