Home Backend Development PHP Tutorial Mobile app interface programming technology - advanced PHP classes and objects for learning and implementation

Mobile app interface programming technology - advanced PHP classes and objects for learning and implementation

Aug 08, 2016 am 09:21 AM
car echo gt name public

  • Create classes and objects
<code><span><span><?php</span><span><span>class</span><span>Car</span>
{</span><span>public</span><span>$name</span> = <span>'汽车'</span>;

   <span>public</span><span><span>function</span><span>getName</span><span>()</span>
   {</span><span>return</span><span>$this</span>->name;
   }
}

<span>$car</span> = <span>new</span> Car();

<span>echo</span><span>$car</span>->name.<span>'<br>'</span>;
<span>echo</span><span>$car</span>->getName();</span></span></code>
Copy after login
  • Attributes of a class

The attribute declaration starts with the keywords public, protected or private, followed by an ordinary variable declaration. Attribute variables can be initialized with a default value, and the default value must be a constant.

The meaning of access control keywords is:
public: public
protected: protected
private: Private ones

are public by default and can be accessed by the outside world. Generally, the properties or methods of an object are accessed through the -> object operator. For static properties, use :: double colon to access them. When called inside a class member method, you can use the $this pseudo variable to call the properties of the current object.

Protected properties and private properties do not allow external calls, but can be called within the member methods of the class.

  • Class methods

Like attributes, class methods also have public, protected and private access control.

Modified with the keyword static, it is called a static method. Static methods do not need to instantiate objects and can be called directly through the class name. The operator is a double colon::.

<code><span><span><?php</span><span><span>class</span><span>Car</span> {</span><span>public</span><span>$speed</span> = <span>0</span>;
    <span>//增加speedUp方法,使speed加10</span><span><span>function</span><span>speedUp</span><span>()</span>
    {</span><span>$this</span>->speed +=<span>10</span>;
    }

   <span>public</span><span>static</span><span>$name</span> = <span>'jarlen'</span>;

   <span>public</span><span>static</span><span><span>function</span><span>getSpeed</span><span>()</span>
   {</span><span>return</span><span>'ja'</span>;
   }

}
<span>$car</span> = <span>new</span> Car();
<span>$car</span>->speedUp();
<span>echo</span><span>$car</span>->speed;

<span>echo</span><span>'<br><br>'</span>.Car::<span>$name</span>.<span>'<br><br>'</span>;

<span>echo</span> Car::getSpeed();</span></span></code>
Copy after login

Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above has introduced the mobile app interface programming technology - PHP advanced classes and objects for learning and implementation, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement of this Website
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

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 ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Fix: Snipping tool not working in Windows 11 Fix: Snipping tool not working in Windows 11 Aug 24, 2023 am 09:48 AM

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

What is the difference between the developer version and the public version of iOS? What is the difference between the developer version and the public version of iOS? Mar 01, 2024 pm 12:55 PM

Every year before Apple releases a new major version of iOS and macOS, users can download the beta version several months in advance and experience it first. Since the software is used by both the public and developers, Apple has launched developer and public versions, which are public beta versions of the developer beta version, for both. What is the difference between the developer version and the public version of iOS? Literally speaking, the developer version is a developer test version, and the public version is a public test version. The developer version and the public version target different audiences. The developer version is used by Apple for testing by developers. You need an Apple developer account to download and upgrade it.

Five selected Go language open source projects to take you to explore the technology world Five selected Go language open source projects to take you to explore the technology world Jan 30, 2024 am 09:08 AM

In today's era of rapid technological development, programming languages ​​are springing up like mushrooms after a rain. One of the languages ​​that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

EV highway range test reveals Model 3 is not alone in range overestimation — Mercedes EQE leads the pack as BMW i5 disappoints EV highway range test reveals Model 3 is not alone in range overestimation — Mercedes EQE leads the pack as BMW i5 disappoints Jun 22, 2024 am 10:09 AM

Much has been said about flawed EV range testing methodology, but a recent test by YouTube channel Carwow (watch the video below the text) drove the point home, as none of the six electric cars in the test managed to reach the claimed range. Accordin

Go language development essentials: 5 popular framework recommendations Go language development essentials: 5 popular framework recommendations Mar 24, 2024 pm 01:15 PM

&quot;Go Language Development Essentials: 5 Popular Framework Recommendations&quot; As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

How to Fix Can't Connect to App Store Error on iPhone How to Fix Can't Connect to App Store Error on iPhone Jul 29, 2023 am 08:22 AM

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Deal | Tesla Model 3 Long Range AWD regains full $7,500 tax incentive, drops to below $40,000 Jun 19, 2024 am 09:55 AM

Shortly after Tesla launched the Model 3 Highland refresh towards the end of last year, the US federal EV tax incentive rules changed, cutting the potential discount in half for eligible buyers because of Tesla's use of Chinese LFP cells in the new M

See all articles