search
HomeBackend DevelopmentPHP TutorialIt's Friday, la la la la - LAMP PHP's OOP, - lampoop_PHP tutorial

It’s Friday la la la la -LAMP PHP’s OOP, -lampoop

 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1077890.htmlTechArticleIt’s Friday la la la la -LAMP PHP’s OOP, -lampoop hi Friday~~ 1. LAMP Configuration Complete Part 5. LAMP Configuration Environment Optimization 5.4 Working Principle of Virtual Host Apache virtual host. virtual-h...
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 Performance Tuning for High Traffic WebsitesPHP Performance Tuning for High Traffic WebsitesMay 14, 2025 am 12:13 AM

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

Dependency Injection in PHP: Code Examples for BeginnersDependency Injection in PHP: Code Examples for BeginnersMay 14, 2025 am 12:08 AM

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

PHP Performance: is it possible to optimize the application?PHP Performance: is it possible to optimize the application?May 14, 2025 am 12:04 AM

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

PHP Performance Optimization: The Ultimate GuidePHP Performance Optimization: The Ultimate GuideMay 14, 2025 am 12:02 AM

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

PHP Dependency Injection Container: A Quick StartPHP Dependency Injection Container: A Quick StartMay 13, 2025 am 12:11 AM

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Dependency Injection vs. Service Locator in PHPDependency Injection vs. Service Locator in PHPMay 13, 2025 am 12:10 AM

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHP performance optimization strategies.PHP performance optimization strategies.May 13, 2025 am 12:06 AM

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHP Email Validation: Ensuring Emails Are Sent CorrectlyPHP Email Validation: Ensuring Emails Are Sent CorrectlyMay 13, 2025 am 12:06 AM

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

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

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

mPDF

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),