This gets quite a bit more complex than returning simple types, or even arrays. The first thing to do is to declare an extension-wide global class ptr along with the methods available in this object you are creating.

Next, in our module_init function we initialize and register our class definition.

And then we create our object factory function which will return an instantiated object.

From user space it would be called like this:

<?php
  $obj 
my_object();
  
$obj->add(...);
?>
If you want to have the more traditional class instantiation syntax and want to have a constructor run for it. eg.

<?php
  $obj 
= new my_class();
?>
Then create a constructor function:

Note the use of this_ptr here.

If you want to access properties from within one of the methods, you can do this: