Last active
December 28, 2015 21:49
-
-
Save cebe/7566916 to your computer and use it in GitHub Desktop.
static property overiding in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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