1. Since we put the program in /usr/local/bin in the last two classes. Each edit requires sudo. In this lesson, we use PHPSTORM to edit the code, copy it specifically, and then put it in a folder called home/godpro.
2. Now let’s make a copy script to automatically copy files under home/godpro to /usr/local/bin
1. We create a file called done under godpro.
<span style="color: #0000ff;">echo</span> your password | sudo -S /bin/bash -c ' cp god* /usr/local/bin'
<span style="color: #0000ff;">然后给这个done chmod</span> +x <span style="color: #0000ff;">done</span>
3. In this class, you will learn about PHP classes
<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>
Today we first learn how to write static methods and static properties.
4. We set a requirement: when we execute godinit, our God will ask you questions: 1. What is the name of your project? 2. Ask who is the author of the project? After answering, save these 2 values in godinit2 static variables:
The first knowledge point that needs to be supplemented is: getting the characters entered by the user from the standard input $getstr=fgets(STDIN);
Okay, let’s create a new file godinit and create a class:
<span style="color: #000000;">php </span><span style="color: #0000ff;">class</span> godinit <span style="color: #008000;">//</span><span style="color: #008000;">创建一个类,godinit</span> <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><span style="color: #008000;">声明一个静态属性$VERSION</span> <span style="color: #0000ff;">static</span> <span style="color: #800080;">$prj_name</span>=""; <span style="color: #008000;">//</span><span style="color: #008000;">声明一个静态属性项目名称</span> <span style="color: #0000ff;">static</span> <span style="color: #800080;">$prj_author</span>='shenyi'; <span style="color: #008000;">//</span><span style="color: #008000;">声明一个静态属性项目作者</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> init() <span style="color: #008000;">//</span><span style="color: #008000;">静态方法 init</span> <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><span style="color: #008000;">从标准输入中获取用户输入的字符并赋值给静态属性$prj_name</span> <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><span style="color: #008000;">return ""</span> <span style="color: #000000;"> } } </span>?>
If we want to change static variables inside a class, we can use self; self represents the class itself, and :: represents calling the variables or functions of the class itself.
Now the god file should be:
<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>?>
Copyright Statement: Note organizer Desperado loves freedom and advocates sharing. But this note is derived from "The First Stage of PHP Devil Training Course" by teacher Shen Yi of www.jtthink.com (Programmer on the Road). This study note was first published on the blog. If you need to reprint it, please respect the teacher's work and retain the signature of Teacher Shen Yi and the course source address.
Previous lesson: Teacher Shen Yi’s special PHP training notes (2)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
