pub fn object_override<T: RegisteredClass>(mut self) -> Self {
        extern "C" fn create_object<T: RegisteredClass>(ce: *mut ClassEntry) -> *mut ZendObject {
            // SAFETY: After calling this function, PHP will always call the constructor
            // defined below, which assumes that the object is uninitialized.
            let obj = unsafe { ZendClassObject::<T>::new_uninit(ce.as_ref()) };
            obj.into_raw().get_mut_zend_obj()
        }

        zend_fastcall! {
            extern fn constructor<T: RegisteredClass>(ex: &mut ExecuteData, _: &mut Zval) {
                let Some(ConstructorMeta { constructor, .. }) = T::constructor() else {
                    PhpException::default("You cannot instantiate this class from PHP.".into())
                        .throw()
                        .expect("Failed to throw exception when constructing class");
                    return;
                };

                let this = match constructor(ex) {
                    ConstructorResult::Ok(this) => this,
                    ConstructorResult::Exception(e) => {
                        e.throw()
                            .expect("Failed to throw exception while constructing class");
                        return;
                    }
                    ConstructorResult::ArgError => return,
                };

                let Some(this_obj) = ex.get_object::<T>() else {
                    PhpException::default("Failed to retrieve reference to `this` object.".into())
                        .throw()
                        .expect("Failed to throw exception while constructing class");
                    return;
                };

                this_obj.initialize(this);
            }
        }

        debug_assert_eq!(
            self.name.as_str(),
            T::CLASS_NAME,
            "Class name in builder does not match class name in `impl RegisteredClass`."
        );
        self.object_override = Some(create_object::<T>);
        self.method(
            {
                let mut func = FunctionBuilder::new("__construct", constructor::<T>);
                if let Some(ConstructorMeta { build_fn, .. }) = T::constructor() {
                    func = build_fn(func);
                }
                func
            },
            MethodFlags::Public,
        )
    }
Overrides the creation of the Zend object which will represent an
instance of this class.

# Parameters

* `T` - The type which will override the Zend object. Must implement
[`RegisteredClass`] which can be derived using the
[`php_class`](crate::php_class) attribute macro.

# Panics

Panics if the class name associated with `T` is not the same as the
class name specified when creating the builder.
src/builders/class.rs