Skip to content

Instantly share code, notes, and snippets.

@qRoC
Last active May 16, 2018 11:19
Show Gist options
  • Save qRoC/528fc176975ec97eae48063f9150211c to your computer and use it in GitHub Desktop.
Save qRoC/528fc176975ec97eae48063f9150211c to your computer and use it in GitHub Desktop.
Generic PHP interface (version < 5.4.1)
<?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