search
HomeBackend DevelopmentPHP TutorialClasses and Objects in PHP5_PHP教程

Classes and Objects in PHP5_PHP教程

Jul 13, 2016 pm 05:21 PM
andphp5definitionobjectModelkindprogrammingFor

Classes and Objects in PHP5_PHP教程 第 1 页 第一节 面向对象编程 [1]
Classes and Objects in PHP5_PHP教程 第 2 页 第二节 对象模型 [2]
Classes and Objects in PHP5_PHP教程 第 3 页 第三节 定义一个类 [3]
Classes and Objects in PHP5_PHP教程 第 4 页 第四节 构造函数和析构函数 [4]
Classes and Objects in PHP5_PHP教程 第 5 页 第五节 克隆 [5]
Classes and Objects in PHP5_PHP教程 第 6 页 第六节 访问属性和方法 [6]
Classes and Objects in PHP5_PHP教程 第 7 页 第七节 类的静态成员 [7]
Classes and Objects in PHP5_PHP教程 第 8 页 第八节 访问方式 [8]
Classes and Objects in PHP5_PHP教程 第 9 页 第九节 绑定 [9]
Classes and Objects in PHP5_PHP教程 第 10 页 第十节 抽象方法和抽象类 [10]
Classes and Objects in PHP5_PHP教程 第 11 页 第十一节 重载 [11]
Classes and Objects in PHP5_PHP教程 第 12 页 第十二节 类的自动加载 [12]
Classes and Objects in PHP5_PHP教程 第 13 页 第十三节 对象串行化 [13]
Classes and Objects in PHP5_PHP教程 第 14 页 第十四节 命名空间 [14]
Classes and Objects in PHP5_PHP教程 第 15 页 第十五节 Zend引擎的发展 [15]

Classes and Objects in PHP5_PHP教程

作者:Leon Atkinson 翻译:Haohappy

  面向对象编程被设计来为大型软件项目提供解决方案,尤其是多人合作的项目. 当源代码增长到一万行甚至更多的时候,每一个更动都可能导致不希望的副作用. 这种情况发生于模块间结成秘密联盟的时候,就像第一次世界大战前的欧洲.

//haohappy注:喻指模块间的关联度过高,相互依赖性太强.更动一个模块导致其它模块也必须跟着更动.

  想像一下,如果有一个用来处理登录的模块允许一个信用卡处理模块来分享它的数据库连接. 当然出发点是好的,节省了进行另一个数据库连接的支出.然而有时,登录处理模块改变了其中一个变量的名字,就可能割断了两者间的协议.导致信用卡模块的处理出错,进而导致处理发票的模块出错. 很快地,体系中所有无关的模块都可能由此出错.

  因此,我觉得有点戏剧性地,绝大多数程序员都对耦合和封装心存感激. 耦合是两个模块间依赖程度的量度. 耦合越少越好.我们希望能够从已有的项目中抽走一个模块并在另一个新项目中使用.

我们也希望在某个模块内部大规模的更动而不用担心对其他模块的影响. 封装的原则可以提供这个解决方案.模块被看待成相对独立,并且模块间的数据通信通过接口来进行. 模块不通过彼此的变量名来窥探另一个模块,它们通过函数来礼貌地发送请求.

  封装是你可以在任何编程语言中使用的一个原则. 在PHP和许多面向过程的语言中,可以偷懒是很有诱惑的.没有什么可以阻止你通过模块来构建一个假想的WEB. 面向对象编程是使程序员不会违背封装原则的一种方法.


  在面向对象编程中,模块被组织成一个个对象. 这些对象拥有方法和属性. 从抽象的角度来看,方法是一个对象的所做的动作,而属性是对象的特性.从编程角度来看,方法就是函数而属性是变量. 在一个理想化的面向对象体系中,每个部份都是一个对象. 体系由对象及对象间通过方法来形成的联系构成.

  一个类定义了对象的属性. 如果你在烘烤一组甜饼对象,那么类将会是甜饼机. 类的属性和方法是被调用的成员. 人们可以通过说出数据成员或者方法成员来表达.


  每种语言提供了不同的途径来访问对象. PHP从C++中借用概念,提供一个数据类型用来在一个标识符下包含函数和变量。最初设计PHP的时候,甚至PHP3被开发出时,PHP并不打算提供开发超过10万行代码的大型项目的能力。随着PHP和Zend引擎的发展,开发大型项目变得有可能,但无论你的项目规模多大,用类来书写你的脚本将可以让代码实现重用。这是一个好主意,特别当你愿意与别人分享你的代码的时候。

  有关对象的想法是计算机科学上最令人兴奋的概念之一。开始很难掌握它,但我可以保证,一旦你掌握了它,用它的思维来思考将会非常自然。


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532458.htmlTechArticlePage 1 Section 1 Object-oriented Programming [1] Page 2 Section 2 Object Model [2] Section Page 3 Section 3 Defining a Class [3] Page 4 Section 4 Constructors and Destructors [4] Page 5...
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
How do you set the session cookie parameters in PHP?How do you set the session cookie parameters in PHP?Apr 22, 2025 pm 05:33 PM

Setting session cookie parameters in PHP can be achieved through the session_set_cookie_params() function. 1) Use this function to set parameters, such as expiration time, path, domain name, security flag, etc.; 2) Call session_start() to make the parameters take effect; 3) Dynamically adjust parameters according to needs, such as user login status; 4) Pay attention to setting secure and httponly flags to improve security.

What is the main purpose of using sessions in PHP?What is the main purpose of using sessions in PHP?Apr 22, 2025 pm 05:25 PM

The main purpose of using sessions in PHP is to maintain the status of the user between different pages. 1) The session is started through the session_start() function, creating a unique session ID and storing it in the user cookie. 2) Session data is saved on the server, allowing data to be passed between different requests, such as login status and shopping cart content.

How can you share sessions across subdomains?How can you share sessions across subdomains?Apr 22, 2025 pm 05:21 PM

How to share a session between subdomains? Implemented by setting session cookies for common domain names. 1. Set the domain of the session cookie to .example.com on the server side. 2. Choose the appropriate session storage method, such as memory, database or distributed cache. 3. Pass the session ID through cookies, and the server retrieves and updates the session data based on the ID.

How does using HTTPS affect session security?How does using HTTPS affect session security?Apr 22, 2025 pm 05:13 PM

HTTPS significantly improves the security of sessions by encrypting data transmission, preventing man-in-the-middle attacks and providing authentication. 1) Encrypted data transmission: HTTPS uses SSL/TLS protocol to encrypt data to ensure that the data is not stolen or tampered during transmission. 2) Prevent man-in-the-middle attacks: Through the SSL/TLS handshake process, the client verifies the server certificate to ensure the connection legitimacy. 3) Provide authentication: HTTPS ensures that the connection is a legitimate server and protects data integrity and confidentiality.

The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

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 Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Atom editor mac version download

Atom editor mac version download

The most popular open source editor