1. Da wir das Programm in den letzten beiden Klassen in /usr/local/bin abgelegt haben. Für jede Bearbeitung ist Sudo erforderlich. In dieser Lektion verwenden wir PHPSTORM, um den Code zu bearbeiten, ihn gezielt zu kopieren und ihn dann in einem Ordner namens home/godpro abzulegen.
2. Jetzt erstellen wir ein Kopierskript, um Dateien automatisch unter home/godpro nach /usr/local/bin zu kopieren
1. Wir erstellen eine Datei namens done unter godpro.
1 | <span style= "color: #0000ff;" > echo </span> your password | sudo -S /bin/bash -c ' cp god* /usr/local/bin'
|
Nach dem Login kopieren
1 | <span style= "color: #0000ff;" >然后给这个done chmod </span> +x <span style= "color: #0000ff;" >done</span>
|
Nach dem Login kopieren
3. In diesem Kurs lernen Sie PHP-Klassen kennen
1 2 3 4 5 | <span style= "color: #0000ff;" > class </span><span style= "color: #000000;" > godInit
{
</span><span style= "color: #0000ff;" > public </span> <span style= "color: #800080;" > $god_version </span>=<span style= "color: #000000;" >“”;
</span><span style= "color: #0000ff;" > function </span><span style= "color: #000000;" > genConfig() { ……}
}</span>
|
Nach dem Login kopieren
Heute lernen wir zunächst, wie man statische Methoden und statische Eigenschaften schreibt.
4. Wir legen eine Anforderung fest: Wenn wir Godinit ausführen, wird Ihnen unser Gott Fragen stellen: 1. Wie heißt Ihr Projekt? 2. Fragen Sie, wer der Autor des Projekts ist? Speichern Sie nach der Beantwortung diese beiden Werte in den statischen Variablen von godinit2:
Der erste Wissenspunkt, der ergänzt werden muss, ist: Abrufen der vom Benutzer eingegebenen Zeichen aus der Standardeingabe $getstr=fgets(STDIN);
OK, erstellen wir eine neue Datei godinit und eine Klasse:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?<span style= "color: #000000;" >php
</span><span style= "color: #0000ff;" > class </span> godinit <span style= "color: #008000;" >
<span style= "color: #000000;" >{
</span><span style= "color: #0000ff;" > static </span> <span style= "color: #800080;" > $VERSION </span>= "god version is 1.1" ; <span style= "color: #008000;" >
<span style= "color: #0000ff;" > static </span> <span style= "color: #800080;" > $prj_name </span>= "" ; <span style= "color: #008000;" >
<span style= "color: #0000ff;" > static </span> <span style= "color: #800080;" > $prj_author </span>= 'shenyi' ; <span style= "color: #008000;" >
<span style= "color: #0000ff;" > static </span> <span style= "color: #0000ff;" > function </span> init() <span style= "color: #008000;" >
<span style= "color: #000000;" > {
</span><span style= "color: #0000ff;" > echo </span> "input your project name?" .<span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
self</span>::<span style= "color: #800080;" > $prj_name </span>=<span style= "color: #008080;" > fgets </span>(STDIN); <span style= "color: #008000;" >
<span style= "color: #0000ff;" > echo </span> "input your author name?" .<span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
self</span>::<span style= "color: #800080;" > $prj_author </span>=<span style= "color: #008080;" > fgets </span><span style= "color: #000000;" >(STDIN);
</span><span style= "color: #0000ff;" > echo </span> "采集信息如下" .<span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
</span><span style= "color: #0000ff;" > echo </span> self::<span style= "color: #800080;" > $prj_name </span>.<span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
</span><span style= "color: #0000ff;" > echo </span> self::<span style= "color: #800080;" > $prj_author </span>.<span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
</span><span style= "color: #008000;" >
<span style= "color: #000000;" > }
}
</span>?>
|
Nach dem Login kopieren
Wenn wir statische Variablen innerhalb einer Klasse ändern möchten, können wir self verwenden; self repräsentiert die Klasse selbst und :: repräsentiert den Aufruf der Variablen oder Funktionen der Klasse selbst.
Die God-Datei sollte jetzt lauten:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <span style= "color: #008000;" >#</span><span style= "color: #008000;" >!/usr/local/bin/php</span>
<?<span style= "color: #000000;" >php
</span><span style= "color: #0000ff;" > require </span>( 'god_func7' <span style= "color: #000000;" >);
</span><span style= "color: #0000ff;" > require </span>( "godint.php" <span style= "color: #000000;" >);
</span><span style= "color: #800080;" > $result </span>= '' <span style= "color: #000000;" >;
</span><span style= "color: #0000ff;" > if </span>(<span style= "color: #800080;" > $argc </span>>=2<span style= "color: #000000;" >)
{
</span> '-v' ==<span style= "color: #800080;" > $argv </span>[1] && <span style= "color: #800080;" > $result </span>=godinit::<span style= "color: #800080;" > $VERSION </span><span style= "color: #000000;" >;
</span> 'make' ==<span style= "color: #800080;" > $argv </span>[1] && <span style= "color: #800080;" > $result </span>=godinit::<span style= "color: #000000;" >make();
</span> 'init' ==<span style= "color: #800080;" > $argv </span>[1] && <span style= "color: #800080;" > $result </span>=godinit::<span style= "color: #000000;" >init();
}
</span><span style= "color: #0000ff;" > echo </span> <span style= "color: #800080;" > $result </span><span style= "color: #000000;" >;
</span><span style= "color: #0000ff;" > echo </span> <span style= "color: #ff00ff;" >PHP_EOL</span><span style= "color: #000000;" >;
</span>?>
|
Nach dem Login kopieren
Urheberrechtserklärung: Hinweis-Organisator Desperado liebt die Freiheit und befürwortet das Teilen. Aber dieser Hinweis stammt von www.jtthink.com (Programmer on the Road) „The First Stage of PHP Devil Training Course“ von Lehrer Shen Yi. Diese Studiennotiz wurde zuerst im Blog veröffentlicht. Wenn Sie sie erneut drucken müssen, respektieren Sie bitte die Arbeit des Lehrers und behalten Sie die Unterschrift von Lehrer Shen Yi und die Kursquellenadresse.
Vorherige Lektion: Spezielle PHP-Trainingsnotizen von Lehrer Shen Yi (2)