Last active
May 16, 2018 11:19
-
-
Save qRoC/528fc176975ec97eae48063f9150211c to your computer and use it in GitHub Desktop.
Generic PHP interface (version < 5.4.1)
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 | |
/// Work in PHP < 5.4.1 | |
interface ITest { | |
public function testSelf(self $test); | |
} | |
class Test implements ITest { | |
private $a = 10; | |
public function testSelf(self $test) { | |
echo $test->a; | |
} | |
} | |
class Test2 extends Test { | |
private $a = 11; | |
public function testSelf(self $test) { | |
echo $test->a; | |
} | |
} | |
$test = new Test(); | |
$test->testSelf($test); | |
echo PHP_EOL; | |
$test2 = new Test2(); | |
$test2->testSelf($test2); | |
// result: | |
// 10 | |
// 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment