PHP object-oriented constructor and destructor

不言
Release: 2023-03-29 22:10:02
Original
1409 people have browsed it

This article mainly introduces the constructor and destructor of PHP object-oriented, which has certain reference value. Now I share it with you. Friends in need can refer to it

Constructor

For a class with a constructor, this method will be called every time it is instantiated, which is suitable for initialization work.

Example

class MyClass { // 构造函数 public function __construct($str) { echo $str; } } // 实例化对象 $c1= new MyClass('abc');
Copy after login

Destructor

When all references to an object are deleted, or are explicitly destroyed, or when the program ends ,implement.

Example

';
Copy after login

Related recommendations:

php object-oriented encapsulation

php object-oriented Classes and instantiated objects


The above is the detailed content of PHP object-oriented constructor and destructor. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!