/** * Test late static binding * * Pre-conditions: * Slim app is extended by Derived class and instantiated; * Derived class overrides the 'getDefaultSettings' function and adds an extra default config value * Test that the new config value exists * * Post-conditions: * Config value exists and is equal to expected value */ public function testDerivedClassCanOverrideStaticFunction() { $app = new Derived(); $this->assertEquals($app->config("late-static-binding"), true); }
echo __METHOD__ . "()\n"; } } class Derived extends Test { function __construct() { echo __METHOD__ . "()\n"; parent::__construct(); } static function f() { new Derived(); } } Derived::f(); class TestPriv { private function __construct() { echo __METHOD__ . "()\n"; } static function f() { new TestPriv(); } } TestPriv::f(); class DerivedPriv extends TestPriv { function __construct()
<?php require "tests.php"; require "director_thread.php"; // No new functions check::functions(array(millisecondsleep, foo_stop, foo_run, foo_do_foo)); // No new classes check::classes(array(director_thread, Foo)); // now new vars check::globals(array(foo_val)); class Derived extends Foo { function do_foo() { $this->val = $this->val - 1; } } $d = new Derived(); $d->run(); if ($d->val >= 0) { check::fail($d->val); } $d->stop(); check::done();
} public function f() { echo "Inside " . __METHOD__ . "\n"; } } class Derived extends Base { public function f() { echo "Inside " . __METHOD__ . "\n"; } } $b1 = new Base(); $b1->b(); $d1 = new Derived(); $d1->b(); echo "-----------------------------\n"; // see about :: in interfaces interface I1 { const CON1 = 123; const CON2 = I1::CON1; const CON3 = self::CON1; function f(); } var_dump(I1::CON1); $intName = 'I1'; var_dump($intName::CON1); var_dump(I1::CON2); var_dump(I1::CON3);
public function __sleep() { // again, merge our members with our parent's return array_merge(array("Leafqux", "*zaz", "blah"), parent::__sleep()); }
<?php class Base { public static function __callStatic($method, $args) { $klass = get_called_class(); echo "class {$klass}\n"; } } class Derived extends Base { } Base::foo(); Derived::foo();
<?php class Base { const greeting = "Hello<br/>"; } class Derived extends Base { const greeting = "Hello World<br/>"; static function func() { echo parent::greeting; } } echo Base::greeting; // output: Hello echo Derived::greeting; // output: Hello World Derived::func(); // output: Hello
<?php abstract class Base { public static function foo() { $a = 2; static::$x; } } class Derived extends Base { public static $x; } $a = new Derived(); $a->foo(); echo "Done\n";