Title: Classes not working in Functions!
Last modified: August 20, 2016

---

# Classes not working in Functions!

 *  [chemdream](https://wordpress.org/support/users/chemdream/)
 * (@chemdream)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/classes-not-working-in-functions/)
 * Guys, what am I missing?
 * I am writing a plugin, that includes something like: class.php
 * In class:
    class random_class {
 *  function unique_activate_function() {
    error_log(“this worked”) }
 * }
 * my main file:
 * $object = new random_class;
 * $object->unique_activate_function(); //works perfect!
 * register_activation_hook(__FILE__, ‘activate_random_plugin’);
 * function activate_random_plugin() {
    global $object $object->unique_activate_function();//
   FAILS }

Viewing 1 replies (of 1 total)

 *  Thread Starter [chemdream](https://wordpress.org/support/users/chemdream/)
 * (@chemdream)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/classes-not-working-in-functions/#post-2556773)
 * If I declare the new object within the function, it works perfect.
 * But referencing it in the functions parms, or accessing it via “global” does 
   not work…

Viewing 1 replies (of 1 total)

The topic ‘Classes not working in Functions!’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [chemdream](https://wordpress.org/support/users/chemdream/)
 * Last activity: [14 years, 5 months ago](https://wordpress.org/support/topic/classes-not-working-in-functions/#post-2556773)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
