php __construct() 和 init() 有什么区别

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3747114/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:57:43  来源:igfitidea点击:

What's the difference between __construct() and init()

phpzend-framework

提问by tom

I was wondering what is the difference between __construct()and init()functions in a PHP application, more particularly in a Zend Framework application.

我想知道PHP 应用程序中的__construct()init()函数之间有什么区别,尤其是在 Zend Framework 应用程序中。

回答by Colin Hebert

init() is called by the constructor.

init() 由构造函数调用。

init() isn't defined in the specification of PHP, it's only a method available with the Zend Framework to help initialize without having to rewrite the constructor yourself.

init() 没有在 PHP 规范中定义,它只是 Zend Framework 提供的一种方法,可以帮助初始化,而无需自己重写构造函数。



On the same topic :

在同一主题上:

回答by Sergey Eremin

__constructis a php magicmethod. It always exists and is called on object creation. init() is just a reguar method usually used in ZF..

__construct是一个 php魔法方法。它始终存在并在创建对象时调用。init() 只是 ZF 中常用的 reguar 方法。