首页 > 解决方案 > 初始化类已经抛出缺少的参数

问题描述

我不知道我在做什么错了。甚至没有使用该函数,而且我已经在错误日志中丢失了左右参数,奇怪的是它仍然可以完成工作并像我的其他类一样返回想要的信息,但我不知道为什么这两个不只是闭嘴.

<?php    
  include_once "classes/getT.php";
  include_once "classes/getC.php";

  $getT = new getT();
  $getC = new getC();
?>

两个包含的代码完全相似,只是用于 CURL 和其他变量传递的不同 URL。

<?php
   class getT{
    function getT ($tID, $count, $offset) {
      $url = "...?tId=$tID&count=$count&offset=$offset";
      $curl = curl_init();
      curl_setopt($curl, CURLOPT_URL, $url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);

      $curl_response = curl_exec($curl);
      curl_close($curl);
      return $curl_response;
    }
  }
?>

标签: php

解决方案


Seems like you try to use old-style php constructor (via method with name same as name of the class). It have three arguments, and you must provide they when you create new object of your class:

  $getT = new getT($tID, $count, $offset);
  $getC = new getC($tID, $count, $offset);

推荐阅读