Skip to content

Instantly share code, notes, and snippets.

@raphaeldealmeida
Created February 21, 2012 16:55
Show Gist options
  • Save raphaeldealmeida/1877353 to your computer and use it in GitHub Desktop.
Save raphaeldealmeida/1877353 to your computer and use it in GitHub Desktop.
PHP 5.3 - Late Static Binding
<?php
class Foo{
protected static function speak(){
echo __METHOD__, "\n\r";
return 'Hi';
}
public static function sayHi(){
//return self::speak(); // PHP 5.2 <=
return static::speak(); //PHP 5.3
}
}
class Bar extends Foo {
protected static function speak(){
echo __METHOD__, "\n\r";
return 'Hello';
}
}
/*
output:
Bar::speak
Hello
*/
echo Bar::sayHi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment