Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php // Interface: defines WHAT, not HOW interface Payable { public function charge(float $amount): bool; } // Abstract class: defines WHAT + some HOW abstract class BasePayment implements Payable { protected string $currency = "USD"; // Shared implementation public function formatAmount(float $amount): string { return number_format($amount, 2) . " " . $this->currency; } // Still requires implementation abstract public function charge(float $amount): bool; } class StripePayment extends BasePayment { public function charge(float $amount): bool { echo "Charging " . $this->formatAmount($amount) . " via Stripe"; return true; } }
Result
Open