[wp-trac] [WordPress Trac] #14920: Noop function called and WP_Dependencies constructors conceptuall broken

WordPress Trac wp-trac at lists.automattic.com
Tue Sep 21 10:33:39 UTC 2010

#14920: Noop function called and WP_Dependencies constructors conceptuall broken
 Reporter:  hakre         |       Owner:                 
     Type:  defect (bug)  |      Status:  new            
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:                 
 Severity:  normal        |    Keywords:                 
 See [15639]

 In PHP4, extending a class and providing the PHP 4 constructor function
 (function named as class) will override the existing, complex constructor
 structure that is part of class WP_Dependencies.

 So at first, the constructor is conceptually broken:

 In #10861 it was argumented the complex structure is for extending, this
 little PHP 4 code demonstrates that this principle does not work:

  * PHP 4 constructors and inheritance
 class foo_parent {
         function foo_parent() {
                 printf("%s()\n", __FUNCTION__);
         function __constructor() {
                 printf("%s()\n", __FUNCTION__);

 class foo extends foo_parent {
         function foo() {
                 printf("%s()\n", __FUNCTION__);

 $test = new foo();


 X-Powered-By: PHP/4.4.2
 Content-type: text/html


 As the constructor only need to call itself (if it's non-overridden), it
 is already called. If the extending class needs it's own constructor, it
 only needs to define it. In this case, the parent's constructor won't be
 called any longer.

 Next to the fact that it does not what it is inteded for, PHP 5 is
 compatible with PHP 4 constructors, so there is no need to introduce a
 expensive variable function call to a function that is NOOP ing.

 But that's not the end. As child classes (e.g. WP_Scripts) use the PHP 5
 constructor only, their parent implementation is not called making it
 useless. Instead they only need to implement their PHP 4 constructor. to
 have the same behavior (variables can not be passed by reference with
 variable function calls via {{{call_user_func_array()}}}).

 The current implementation is hard to understand, conceptually broken and
 makes the code hard to read.

Ticket URL: <http://core.trac.wordpress.org/ticket/14920>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software

More information about the wp-trac mailing list