[wp-trac] [WordPress Trac] #21309: Introduce WP_Post class

WordPress Trac wp-trac at lists.automattic.com
Fri Jul 27 05:41:32 UTC 2012


#21309: Introduce WP_Post class
----------------------------+------------------
 Reporter:  scribu          |       Owner:
     Type:  task (blessed)  |      Status:  new
 Priority:  normal          |   Milestone:  3.5
Component:  General         |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |
----------------------------+------------------

Comment (by mikeschinkel):

 Replying to [comment:16 scribu]:
 > > If that's the design pattern we're going to suggest for now, should
 WP_Post be made final to protect us in doing future changes?
 >
 > Yes, if we're going to go with composition instead of inheritance, we
 should use the final keyword. We can remove it later, if necessary.

 This worries me greatly, but I assume there is a discussion thread that
 details the decision somewhere? Would you mind providing a link?

 Reasons it worries me is I would like to be able do doing something like
 this:

 {{{
 class Event_Post extends WP_Post {
   var $start_time;
   var $end_time;
   function duration() {
      return $this->end_time - $this->start_time;
   }
 }}}

 And then being able to do things like this:

 {{{
 foreach( $posts as $post ) {
   if ( is_a( $post, 'WP_Post') ) {
      // Do something that requires a WP_Post object
   }
 }
 }}}
 I can simulate the former with composition, but not in a reliable way, but
 I can't do the latter without composition or using conventions that not
 everyone will follow.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/21309#comment:18>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list