wp-papi / papi

:rocket: WordPress Page Type API with custom fields
https://wp-papi.github.io
MIT License
263 stars 32 forks source link

Class instantiation #192

Closed nlemoine closed 8 years ago

nlemoine commented 8 years ago

I don't know if this can be labelled as a "bug" but here's my issue.

What happened

I'm using an abstract class as a base template for creating page types:

abstract class BaseTemplate extends Papi_Page_Type {

  abstract public function meta();
  abstract public function register();
  public function add_common_boxes() {
    $this->box(...);
  }
}

In my types directory:

SomePageType extends BaseTemplate {
  public function meta() {
    ...
  }
  public function register() {
    $this->add_common_boxes();
    ...
  }
}

What I expected

This pattern worked great in 2.x but in 3.x, an error is thrown: "Cannot instantiate abstract class BaseTemplate" because it's trying to instantiate an abstract class.

But maybe I'm doing it wrong with this pattern? Any thoughts?

frozzare commented 8 years ago

Thanks for your bug report, this is definitely a bug in 3.x, never thought about that you can use a abstract class in this way. The problem is that Papi tries to merge BaseTemplate with SomePageType but isn't checkin for which type of class it is. Will work on a fix for this 👍

nlemoine commented 8 years ago

Thanks for the quick fix! 👍