search
HomeBackend DevelopmentPHP Tutorial礼拜五了啦啦啦啦-LAMP+PHP‘s OOP

周五了啦啦啦啦-LAMP+PHP‘s OOP

  hi

周五咯~~

1、LAMP配置完结篇

五、LAMP配置环境优化

5.4 虚拟主机工作原理

apache的虚拟主机。virtual-host

用不同的域名访问不同的目录——手动模拟dns

修改host文件即可实现。具体就是主机地址 域名

复习

[email protected]:~$ sudo apt-get install apache2

[email protected]:~$ sudo apt-get install php5
然后加载/检查php5.load这个php实现对apache2操作的模块(LAMP的互相,就是模块的启动/连接)
[email protected]:~$ cat /etc/apache2/mods-enabled/php5.load
[email protected]:~$ sudo apt-get install mysql-server

sudo apt-get install apache2 php5 mysql-server php5-mysql

[email protected]:~$ sudo service mysql restart
[email protected]:~$ sudo service apache2 restart

----创建phpinfo探针

先装vim

sudo apt-get install vim

再切换到php的www文件夹,用cd命令

cd /var/www/html(14.4版本)

然后在这里创建一个php文件

sudo vim info.php

写php代码

echo mysql_connect('localhost','root','hanhan123') ? 'Hoho' : 'WTF';

phpinfo();
然后esc键,输入:wq保存退出

http://192.168.1.100/info.php 浏览器输入验证结果

复习结束

5.5 安装phpmyadmin

--

apt-get命令

sudo apt-get install phpmyadmin

sudo ln -s /usr/share/phpmyadmin/ /var/www/pma

 六、服务器集群了解

国内外有很多著名的巨型服务器集群。

用于同时处理大批量的请求

-----------------------------------

2、PHP的OOP编程

四、OOP的高级实践

程序准备

date_default_timezone_set("PRC");
/**
* 1. 类的定义以class关键字开始,后面跟着这个类的名称。类的名称命名通常每个单词的第一个字母大写。
* 2. 定义类的属性
* 3. 定义类的方法
* 4. 实例化类的对象
* 5. 使用对象的属性和方法
*/
class NbaPlayer
{
// 类的属性的定义
public $name="Jordan";// 定义属性
public $height="198cm";
public $weight="98kg";
public $team="Bull";
public $playerNumber="23";

// 类的方法的定义
public function run() {
echo "Running\n";
}

public function jump(){
echo "Jumping\n";
}
public function dribble(){
echo "Dribbling\n";
}
public function shoot(){
echo "Shooting\n";
}
public function dunk(){
echo "Dunking\n";
}
public function pass(){
echo "Passing\n";
}
}

/**
* 1. 类实例化为对象时使用new关键字,new之后紧跟类的名称和一对括号。
* 2. 使用对象可以像使用其他值一样进行赋值操作
*/
$jordan = new NbaPlayer();
// 访问对象的属性使用的语法是->符号,后面跟着属性的名称
echo $jordan->name."\n";
// 调用对象的某个方法使用的语法是->符号,后面跟着方法的名称和一对括号
$jordan->run();
$jordan->pass();

?>

 4.1 继承

也就是对象相似的部分,可以多处使用——避免代码冗余,开发效率提高。

优点:父类中定义的了,子类中无需再次定义——效率高;对于外部,表现一致(父类是一样的);重写,来修改子类。

举个栗子

class Human{
public $name;
public $height;
public $weight;

public function eat($food){
echo $this->name."'s eating".$food."\n";
}
}

人类作为父类,然后nba球员作为子类

class NbaPlayer extends Human{

试着直接通过子类调用父类中的function

$jordan->eat("apple");

输出

Jordan's eating apple

没有问题!子类是可以直接调用父类的属性和方法的!!(在子类的对象上可以直接访问父类中定义的方法和属性)

毕竟从它的意思来看,子类就是父类的延伸。

另外,父类中的属性可以在子类中进行访问(实际上,简单的理解就是,所有的子类都是大于等于父类的对象,想象一下文氏图)

类的继承,用extends,只能跟一个“爸爸”——php的单继承原则

4.2 访问控制

所有的属性和方法都有访问权限的选择——选择可以被谁访问

public:公有,任何地方

protected:受保护的,被自身以及其子类

private:私有,只能被自身访问

举个private的栗子

在Nbaplayer这个子类中,新增加定义

    private $age="44";

public function getAge(){
echo $this->name."'s age is ".$this->age;
}

//试着调用private,直接以及通过内部的public函数
//$jordan->age;
$jordan->getAge();

然后,关于protected,范围紧紧的限制在了父类中和子类中,也就是说,出了子类的定义那个大括号就失效了!

4.3 静态成员

可以简单的理解为常量(?)

static

 

 

bu xiang xie le 

 

1楼rickon
bu xiang xie le 。。楼主真是萌萌哒。加油
Re: 韧还
@rickon,哈,当时输入法也逗逼了,干脆任性!
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

The Enduring Relevance of PHP: Is It Still Alive?The Enduring Relevance of PHP: Is It Still Alive?Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP's Current Status: A Look at Web Development TrendsPHP's Current Status: A Look at Web Development TrendsApr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP vs. Other Languages: A ComparisonPHP vs. Other Languages: A ComparisonApr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP vs. Python: Core Features and FunctionalityPHP vs. Python: Core Features and FunctionalityApr 13, 2025 am 12:16 AM

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP: A Key Language for Web DevelopmentPHP: A Key Language for Web DevelopmentApr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

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.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools