Skip to content

Instantly share code, notes, and snippets.

@cebe
Last active December 28, 2015 21:49
Show Gist options
  • Save cebe/7566916 to your computer and use it in GitHub Desktop.
Save cebe/7566916 to your computer and use it in GitHub Desktop.
static property overiding in php
<?php
class YiiBase
{
public static $app;
public static function test()
{
echo self::$app;
}
public static function testB()
{
echo static::$app;
}
}
class Yii extends YiiBase
{
public static $app;
}
Yii::$app = 42;
// self or reference via YiiBase do not give the Yii property
echo YiiBase::$app . "\n";
echo YiiBase::test(). "\n";
echo Yii::test() . "\n";
echo YiiBase::testB() . "\n";
// only direct access or via static works as excpected
echo Yii::$app . "\n";
echo Yii::testB() . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment