I want to create my object when another object is made. Is it a good idea to create my object by hooking to existing class constructor?

for example if the main class is

class WordPress_Class {
 * Constructor
public function __construct() {
    add_action( 'some_action', array( $this, 'some_WP_Class_Method' ) );

    return true;

Then can I use 'some_action' to create my object:

my_object = new My_Class();

and use it on the same page that WordPress_Class object is used?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.