Kombination von static mit OOP in PHP
Eine Klasse kann sowohl statische Eigenschaften und Methoden als auch normale enthalten.
Schauen wir uns ein Beispiel an. Nehmen wir an, wir haben
eine Klasse Test, die sowohl eine
statische Eigenschaft als auch eine normale hat:
<?php
class Test
{
public static $staticProperty = 'static';
public $usualProperty = 'usual';
}
?>
Lassen Sie uns mit der normalen Eigenschaft der Klasse arbeiten:
<?php
$test = new Test;
echo $test->usualProperty;
?>
Und jetzt verwenden wir die statische Eigenschaft:
<?php
echo Test::$staticProperty;
?>
Erstellen Sie eine Klasse, die sowohl eine normale Methode als auch eine statische Methode hat.