Title: Undefined Function Fatal Error In Plugin Class
Last modified: August 21, 2016

---

# Undefined Function Fatal Error In Plugin Class

 *  Resolved [edtiley](https://wordpress.org/support/users/edtiley/)
 * (@edtiley)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/undefined-function-fatal-error-in-plugin-class/)
 * Building a plugin using Class structure.
 * Want to display the result of a formula, so I created a public function so it
   could be done as needed. Something like:
 *     ```
       public function foo($x,$y) {
          return strval(($x+$y)*2.2) ;
         }
       ```
   
 * I keep getting an undefined function. Finally I put the function in functions.
   php and it works like a champ. So it’s obvious the function isn’t getting loaded.
 * I’ve tried using init and plugins_loaded in add_action calls, but the function
   is still not available.
 * Surely there’s a fairly simple way of making the function available inside the
   plugin without having to hook it. Isn’t there?
 * TIA
    Ed

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

 *  [ianhaycox](https://wordpress.org/support/users/ianhaycox/)
 * (@ianhaycox)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/undefined-function-fatal-error-in-plugin-class/#post-3823369)
 * If foo() is in a class are you calling it correctly ?
 * e.g. within the plugin class,
 * `$this->foo();`
 * or from outside the class, you need a class instance,
 *     ```
       $x = new MyPluginClass();
       $x->foo();
       ```
   
 * or make foo static,
 * `MyPluginClass::foo();`
 * Once foo() in is functions.php, depedning how it’s declared, foo() is probably
   in global scope, so just calling
 * `foo();`
 * would work.
 * Ian.
 *  Thread Starter [edtiley](https://wordpress.org/support/users/edtiley/)
 * (@edtiley)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/undefined-function-fatal-error-in-plugin-class/#post-3823401)
 * Putting it in functions.php makes it globally available.
 * `$this->foo();`
    Bingo! I searched unsuccessfully for that for hours. In all 
   the tuts I’ve read on building class based plugins I don’t think that little 
   construct was explicitly mentioned. Or at least failed to penetrate my grayRAM.
 * Thanks.
 * Ed

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

The topic ‘Undefined Function Fatal Error In Plugin Class’ is closed to new replies.

## Tags

 * [hacks](https://wordpress.org/support/topic-tag/hacks/)
 * [undefined function](https://wordpress.org/support/topic-tag/undefined-function/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 2 participants
 * Last reply from: [edtiley](https://wordpress.org/support/users/edtiley/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/undefined-function-fatal-error-in-plugin-class/#post-3823401)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
