Home >Backend Development >PHP Tutorial >It's Friday, la la la la - LAMP PHP's OOP, - lampoop_PHP tutorial
hi
It’s Friday~~
1. LAMP configuration completion
5. LAMP configuration environment optimization
5.4 Working Principle of Virtual Host
Apache virtual host. virtual-host
Use different domain names to access different directories - manually simulate dns
This can be achieved by modifying the host file. Specifically, it is the host address and domain name
Review
liang@liang-andy:~$ sudo apt-get install apache2
liang@liang-andy:~$ sudo apt-get install php5
Then load/check php5.load, the php module that implements apache2 operation (The interaction between LAMP is the startup/connection of the module)
liang@liang-andy:~$ cat /etc/apache2/mods-enabled/php5.load
liang@liang-andy:~$ sudo apt-get install mysql-server
sudo apt-get install apache2 php5 mysql-server php5-mysql
liang@liang-andy:~$ sudo service mysql restart
liang@liang-andy:~$ sudo service apache2 restart
----Create phpinfo probe
Install vim first
sudo apt-get install vim
Then switch to the www folder of php and use the cd command
cd /var/www/html (version 14.4)
Then create a php file here
sudo vim info.php
Write php code
echo mysql_connect('localhost','root','hanhan123') ? 'Hoho' : 'WTF';
phpinfo();
Then esc key , enter: wq to save and exit
http://192.168.1.100/info.php Browser input verification result
End of review
5.5 Install phpmyadmin
--
apt-get command
sudo apt-get install phpmyadmin
sudo ln -s /usr/share/phpmyadmin/ /var/www/pma
6. Understanding server clusters
There are many famous giant server clusters at home and abroad.
Used to handle large batches of requests simultaneously
----------------------------------
2. OOP programming in PHP
4. Advanced Practice of OOP
Program preparation
date_default_timezone_set("PRC");
/**
* 1. The definition of a class starts with the class keyword, followed by the name of the class. Class names are usually named with the first letter of each word capitalized.
* 2. Define the attributes of the class
* 3. Define the methods of the class
* 4. Instantiate the object of the class
* 5. Use the attributes and methods of the object
*/
class NbaPlayer
{
// Definition of class attributes
public $name="Jordan";//Define attributes
public $height="198cm";
public $weight="98kg";
public $team="Bull";
public $ playerNumber="23";
// Definition of class method
public function run() {
echo "Runningn";
}
public function jump(){
echo "Jumpingn";
}
public function dribble(){
echo "Dribblingn";
}
public function shoot() {
echo "Shootingn";
}
public function dunk(){
echo "Dunkingn";
}
public function pass(){
echo "Passingn" ;
}
}
/**
* 1. Use the new keyword when instantiating a class into an object, followed by new followed by the name of the class and a pair of parentheses.
* 2. Using objects can perform assignment operations just like using other values
*/
$jordan = new NbaPlayer();
// The syntax used to access the properties of an object is the -> symbol, followed by the name of the property
echo $ jordan->name."n";
// The syntax used to call a method of an object is the -> symbol, followed by the name of the method and a pair of brackets
$jordan->run() ;
$jordan->pass();
?>
4.1 Inheritance
That is, similar parts of objects can be used in multiple places - avoiding code redundancy and improving development efficiency.
Advantages: It is defined in the parent class and does not need to be defined again in the subclass - high efficiency; externally, the performance is consistent (the parent class is the same); rewrite to modify the subclass.
Give me a chestnut
class Human{
public $name;
public $height;
public $weight;
public function eat($food){
echo $this-> name."'s eating".$food."n";
}
}
Humans as parent class, and nba players as subclasses
class NbaPlayer extends Human{
Try to call the function in the parent class directly through the subclass
$jordan->eat("apple");
Output
Jordan's eating apple
No problem! Subclasses can directly call the attributes and methods of the parent class! ! (Methods and properties defined in the parent class can be directly accessed on objects of the subclass)
After all, from its meaning, a subclass is an extension of the parent class.
In addition, Attributes in the parent class can be accessed in the subclass (in fact, a simple understanding is that all subclasses are objects greater than or equal to the parent class, imagine a Venn diagram)
For class inheritance, use extends, can only follow one "dad" - the single inheritance principle of PHP
4.2 Access Control
All properties and methods have access permission options - choose who can access it
public: public, anywhere
protected: protected, by itself and its subclasses
private: private, can only be accessed by yourself
Give me a private example
In the Nbaplayer subclass, a new definition is added
private $age="44";
public function getAge(){
echo $this->name."'s age is ".$this->age;
}
//Try to call private, directly and through the internal public function
//$jordan->age;
$jordan->getAge();
Then, Regarding protected, the scope is tightly limited to the parent class and the subclass. In other words, the curly brackets will become invalid after the definition of the subclass!
4.3 Static members
can be simply understood as a constant (?)
static
bu xiang xie le