@@ -427,7 +427,7 @@ pub struct ClassEntity<T: 'static> {
427427 state_constructor : Rc < StateConstructor > ,
428428 method_entities : Vec < MethodEntity > ,
429429 property_entities : Vec < PropertyEntity > ,
430- parent : Option < Box < dyn Fn ( ) -> & ' static ClassEntry > > ,
430+ parent : Option < String > ,
431431 interfaces : Vec < Interface > ,
432432 constants : Vec < ConstantEntity > ,
433433 bind_class : StateClass < T > ,
@@ -550,7 +550,7 @@ impl<T: 'static> ClassEntity<T> {
550550 /// Register class to `extends` the parent class.
551551 ///
552552 /// *Because in the `MINIT` phase, the class starts to register, so the*
553- /// *closure is used to return the `ClassEntry` to delay the acquisition of*
553+ /// *`ClassEntry` is looked up by name to delay the acquisition of*
554554 /// *the class.*
555555 ///
556556 /// # Examples
@@ -559,10 +559,10 @@ impl<T: 'static> ClassEntity<T> {
559559 /// use phper::classes::{ClassEntity, ClassEntry};
560560 ///
561561 /// let mut class = ClassEntity::new("MyException");
562- /// class.extends(|| ClassEntry::from_globals( "Exception").unwrap() );
562+ /// class.extends("Exception");
563563 /// ```
564- pub fn extends ( & mut self , parent : impl Fn ( ) -> & ' static ClassEntry + ' static ) {
565- self . parent = Some ( Box :: new ( parent ) ) ;
564+ pub fn extends ( & mut self , parent_name : impl Into < String > ) {
565+ self . parent = Some ( parent_name . into ( ) ) ;
566566 }
567567
568568 /// Register class to `implements` the interface, due to the class can
@@ -631,12 +631,14 @@ impl<T: 'static> ClassEntity<T> {
631631 #[ allow( clippy:: useless_conversion) ]
632632 pub ( crate ) unsafe fn init ( & self ) -> * mut zend_class_entry {
633633 unsafe {
634- let parent: * mut zend_class_entry = self
635- . parent
636- . as_ref ( )
637- . map ( |parent| parent ( ) )
638- . map ( |entry| entry. as_ptr ( ) as * mut _ )
639- . unwrap_or ( null_mut ( ) ) ;
634+ let parent: * mut zend_class_entry = if let Some ( ref name) = self . parent {
635+ let entry = ClassEntry :: from_globals ( name) . unwrap_or_else ( |err| {
636+ panic ! ( "Unable to resolve parent class: {}: {}" , name, err) ;
637+ } ) ;
638+ entry. as_ptr ( ) as * mut _
639+ } else {
640+ null_mut ( )
641+ } ;
640642
641643 let class_ce = phper_init_class_entry_ex (
642644 self . class_name . as_ptr ( ) . cast ( ) ,
@@ -800,7 +802,7 @@ impl InterfaceEntity {
800802 /// Register interface to `extends` the interfaces, due to the interface can
801803 /// extends multi interface, so this method can be called multi time.
802804 ///
803- /// *Because in the `MINIT` phase, the class starts to register, so the *
805+ /// *Because in the `MINIT` phase, the class starts to register, a *
804806 /// *closure is used to return the `ClassEntry` to delay the acquisition of*
805807 /// *the class.*
806808 ///
0 commit comments