1. <i id='jj3QK'><tr id='jj3QK'><dt id='jj3QK'><q id='jj3QK'><span id='jj3QK'><b id='jj3QK'><form id='jj3QK'><ins id='jj3QK'></ins><ul id='jj3QK'></ul><sub id='jj3QK'></sub></form><legend id='jj3QK'></legend><bdo id='jj3QK'><pre id='jj3QK'><center id='jj3QK'></center></pre></bdo></b><th id='jj3QK'></th></span></q></dt></tr></i><div id='jj3QK'><tfoot id='jj3QK'></tfoot><dl id='jj3QK'><fieldset id='jj3QK'></fieldset></dl></div>
    <tfoot id='jj3QK'></tfoot>
  2. <legend id='jj3QK'><style id='jj3QK'><dir id='jj3QK'><q id='jj3QK'></q></dir></style></legend>

    <small id='jj3QK'></small><noframes id='jj3QK'>

      • <bdo id='jj3QK'></bdo><ul id='jj3QK'></ul>

      __construct 函数是做什么用的?

      What is the function __construct used for?(__construct 函数是做什么用的?)

      <tfoot id='hYW3j'></tfoot>
      • <bdo id='hYW3j'></bdo><ul id='hYW3j'></ul>
          <legend id='hYW3j'><style id='hYW3j'><dir id='hYW3j'><q id='hYW3j'></q></dir></style></legend>

          <small id='hYW3j'></small><noframes id='hYW3j'>

              <tbody id='hYW3j'></tbody>

            <i id='hYW3j'><tr id='hYW3j'><dt id='hYW3j'><q id='hYW3j'><span id='hYW3j'><b id='hYW3j'><form id='hYW3j'><ins id='hYW3j'></ins><ul id='hYW3j'></ul><sub id='hYW3j'></sub></form><legend id='hYW3j'></legend><bdo id='hYW3j'><pre id='hYW3j'><center id='hYW3j'></center></pre></bdo></b><th id='hYW3j'></th></span></q></dt></tr></i><div id='hYW3j'><tfoot id='hYW3j'></tfoot><dl id='hYW3j'><fieldset id='hYW3j'></fieldset></dl></div>
              • 本文介绍了__construct 函数是做什么用的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我已经注意到 __construct 很多关于类.我做了一些阅读和网上冲浪,但我找不到我能理解的解释.我刚开始接触 OOP.

                I have been noticing __construct a lot with classes. I did a little reading and surfing the web, but I couldn't find an explanation I could understand. I am just beginning with OOP.

                我想知道是否有人可以让我大致了解它是什么,然后是一个如何与 PHP 一起使用的简单示例?

                I was wondering if someone could give me a general idea of what it is, and then a simple example of how it is used with PHP?

                推荐答案

                __construct 是在 PHP5 中引入的,它是定义构造函数的正确方法(在 PHP4 中你使用了构造函数的类).您不需要在类中定义构造函数,但是如果您希望在对象构造中传递任何参数,那么您需要一个.

                __construct was introduced in PHP5 and it is the right way to define your, well, constructors (in PHP4 you used the name of the class for a constructor). You are not required to define a constructor in your class, but if you wish to pass any parameters on object construction then you need one.

                一个例子可能是这样的:

                An example could go like this:

                class Database {
                  protected $userName;
                  protected $password;
                  protected $dbName;
                
                  public function __construct ( $UserName, $Password, $DbName ) {
                    $this->userName = $UserName;
                    $this->password = $Password;
                    $this->dbName = $DbName;
                  }
                }
                
                // and you would use this as:
                $db = new Database ( 'user_name', 'password', 'database_name' );
                

                PHP 手册中解释了其他所有内容:点击此处

                Everything else is explained in the PHP manual: click here

                这篇关于__construct 函数是做什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <tfoot id='8IOQN'></tfoot>

                • <legend id='8IOQN'><style id='8IOQN'><dir id='8IOQN'><q id='8IOQN'></q></dir></style></legend>
                    <tbody id='8IOQN'></tbody>

                        • <bdo id='8IOQN'></bdo><ul id='8IOQN'></ul>
                          <i id='8IOQN'><tr id='8IOQN'><dt id='8IOQN'><q id='8IOQN'><span id='8IOQN'><b id='8IOQN'><form id='8IOQN'><ins id='8IOQN'></ins><ul id='8IOQN'></ul><sub id='8IOQN'></sub></form><legend id='8IOQN'></legend><bdo id='8IOQN'><pre id='8IOQN'><center id='8IOQN'></center></pre></bdo></b><th id='8IOQN'></th></span></q></dt></tr></i><div id='8IOQN'><tfoot id='8IOQN'></tfoot><dl id='8IOQN'><fieldset id='8IOQN'></fieldset></dl></div>

                          <small id='8IOQN'></small><noframes id='8IOQN'>