object orientated php
1.0.0
该存储库包含 PHP 面向对象编程 (OOP) 课程的材料和练习。本课程涵盖 OOP 中的几个关键概念,包括构造函数、继承和可见性。
基于 OOP 的 4 个支柱:封装、抽象、继承和多态性。
在 PHP 中,构造函数是一种特殊的“神奇”方法,在创建对象时会自动调用它。它通常用于初始化对象的属性。在本课程中,您将学习如何在 PHP 类中定义和使用构造函数。
继承是 OOP 中的一个基本概念,它允许您基于现有类定义新类。这允许您重用代码并基于通用类创建更专业的类。本课程将教您如何在 PHP 中使用继承来创建更高效、更有组织的代码。
PHP OOP 中的可见性是指类中属性和方法的可访问性。可见性分为三个级别:
在本课程中,您将学习如何使用这些不同级别的可见性来控制对代码的访问。
- `::` Scope Resolution Operator
- Like the `__toString` method is called when an object is used in a string context.
- Getters and Setters can have property names passed to get around multiple method calls
- An abstract class is a class that **cannot be instantiated on its own** and is typically used as a base class for other classes.
- The abstract class provides properties and funciontality which is shared by all the classes that inherit from it.
- Declared in an abstract class implementation is provided by the classes that inherit from the abstract class.
- if class extends three dimensions shape aka abstract it must implement the abstract method `getVolume`
- Good for:
- You want to provide a common interface for different classes
- You want to enforce certain methods to be implemented by the child class
- You are designing a large functional unit by using the Template Method patter
- Default implementation of a method in an interface
- Objects that can take on many forms
- an instance of an object that can take more than one type is polymorphic
- Injecting this single type is not as usefull `public function updateStockFromFile(string $path, CsvFileReader $fileReader): array`
- Using `instanceof` we can check if the object is of a certain type
- Closure functions
- Abstract classes and methods
- Uml diagrams
- Dependency injection
PHP
面向对象编程
学习-PHP
PHP课程
构造函数
遗产
能见度
封装
抽象
多态性
PHP单元
磷酸二氢钾
命名空间
自动加载
性状
错误处理
MySQL
作曲家
测试-PHP
测试驱动开发