No late static binding in PHP 5 :(

File this under “that’s not what I expected.” More info here.

<?php

class SomeParent
{
  public static function sayMyName()
  {
    print get_class();
  }
}

class SomeChild extends SomeParent
{
}

// prints SomeParent, as of PHP 5.2.1
SomeChild::sayMyName();

?>

Sending the class name from an overridden method in the child class works:

class SomeChild extends SomeParent
{
  public static function sayMyName()
  {
    parent::sayMyName(get_class());
  }
}

…but it kind of sucks to have to remember to do that.

comments: be first!

name
blog (optional)
comment

monthchunks

license

Justinsomnia is licensed under a Creative Commons Attribution 3.0 License.

Please see my Attribution Policy for more information.