<?php
interface KeyInterface {
public function open();
}
class MagnetKey implements KeyInterface {
public function open()
{
print 'open by magnet key:';
$this->slide();
}
private function slide()
{
print 'slide down.';
}
}
class TurnKey implements KeyInterface {
public function open()
{
print 'open by turn key:';
$this->insert();
$this->turn();
}
private function insert()
{
print 'insert key.';
}
private function turn()
{
print 'turn key.';
}
}
class Key {
public function open()
{
print 'open door:';
$this->insert();
$this->turn();
}
private function insert()
{
print 'insert key.';
}
private function turn()
{
print 'turn key.';
}
}
class MagnetKeOld extends Key {
public function open() {
print 'open by magnet key:';
$this->insert();
$this->slide();
}
private function slide()
{
print 'slide key.';
}
}
$k = new TurnKey();
$k->open();
$mk = new MagnetKey();
$mk->open();
interface Testable {
public function test();
}
interface MyCountable {
public function count();
}
abstract class MyAbstract {
public abstract function test();
}
class MyClass implements Testable, MyCountable {
public function test() {
print 'this is test method';
}
public function count() {
print 'this is count method';
}
}
$o = new MyClass();
$o->test();
$o->count();
open by turn key:insert key.turn key.open by magnet key:slide down.this is test methodthis is count method
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
open by turn key:insert key.turn key.open by magnet key:slide down.this is test methodthis is count method