Skip to content

Instantly share code, notes, and snippets.

@papayasoft
Last active August 29, 2015 13:58
Show Gist options
  • Save papayasoft/10353046 to your computer and use it in GitHub Desktop.
Save papayasoft/10353046 to your computer and use it in GitHub Desktop.
Late static binding in PHP 5.3: The difference between self:: and static::
<?php
class MyBase
{
public static function myMethod()
{
return 'Called MyBase::myMethod()';
}
public static function doSomethingSelf()
{
return self::myMethod();
}
public static function doSomethingStatic()
{
return static::myMethod();
}
}
class MyChild extends MyBase
{
public static function myMethod()
{
return 'Called MyChild::myMyMethod()';
}
}
function o($s)
{
echo $s . PHP_EOL;
}
o(MyChild::doSomethingSelf());
o(MyChild::doSomethingStatic());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment