rfc:lsb_parentself_forwarding

This is an old revision of the document!


Request for Comments: LSB, parent::/self:: forwarding

  • Version: 1.0
  • Date: 2008-07-22
  • Author: Etienne Kneuss colder@php.net
  • Status: Accepted

Introduction

This RFC covers the change that occured to Late Static Bindings (LSB) prior to it's first alpha release.

Terms and concepts

LSB works by passing the original call info to the function, used then by static:: or get_called_class to get the original class name used. This information will only be useful in case a fallback occurs, which takes place when you call a static method that only exists in one of the parent classes. <code php> <?php

class A {
   public static function who() {
      return get_called_class();
   }
}
class B extends A {
   
}
class C extends B {
} 
echo C::who(); // C

?> </code php>

Now let's say that you want to overwrite who in B, but still rely on A's who():

<code php> <?php

class A {
   public static function who() {
      return get_called_class();
   }
}
class B extends A {
   public static function who() {
       /* do stuff.. */
       /* call A's who() */
   }  
}
class C extends B {
} 
echo C::who(); // ??

?> </code php>

Now, depending on how you call A's who() from B::who(), you might get different results for the c::who() call:

C, if the call was {{forwarding}}
A, if the call wasn't {{forwarding}}.

The change

Previously, A::who() and parent::who() would be non-forwarding.

Proposal and Patch

Nothing needs to be patched here. Just use this template at your discretion.

Rejected Features

Automated voting system.

More about RFCs

Changelog

rfc/lsb_parentself_forwarding.1216734937.txt.gz · Last modified: 2017/09/22 13:28 (external edit)