Skip to content

Instantly share code, notes, and snippets.

@tanakahisateru
Created February 16, 2017 14:31
Show Gist options
  • Select an option

  • Save tanakahisateru/5c1832f60646cd56c5bdbf50265f3374 to your computer and use it in GitHub Desktop.

Select an option

Save tanakahisateru/5c1832f60646cd56c5bdbf50265f3374 to your computer and use it in GitHub Desktop.
<?php
class BaseObject
{
public function differentStaticMethodCallingStyle()
{
return [
'self::' => self::staticMethod(),
'static::' => static::staticMethod(),
'$this->' => $this->staticMethod(),
];
}
protected static function staticMethod()
{
return "base object called";
}
}
class ExtendedObject extends BaseObject
{
protected static function staticMethod()
{
return "extended object called";
}
}
print_r((new ExtendedObject())->differentStaticMethodCallingStyle());
// Array
// (
// [self::] => base object called
// [static::] => extended object called
// [$this->] => extended object called
// )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment