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
測試驅動開發