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
What's the difference between __construct() and init()
提问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 方法。