duanjue7508 2011-11-29 14:54
浏览 76

OOP php方法 - 将变量传入或从对象内部传递

I am new to OOP and have written a products class. All is working fine but I am unsure which of the below version of a method within this class is best?

The first gets the variables from within the object and the second passes the variables into the class. Both work. I originally had it as the first version but things seems to be running slow and then changed it to the second.

 public function getProductURLstart(){  

    $select = "SELECT l.URL, p.id FROM logins AS l
    INNER JOIN Pages AS p ON l.id = p.clientID 
    WHERE l.id = '$this->skID' AND p.productPage = 1";

    $res = mssql_query($select);
    $r = mssql_fetch_row($res);     

    $url = trim($r[0]); 
    $page_id = $r[1];

    return  $url .'/index.aspx?pageID='. $page_id . '&prodID=$this->prodID';

}

OR

 static function getProductURLstart($skID, $prodId){    

    $select = "SELECT l.URL, p.id FROM logins AS l
    INNER JOIN Pages AS p ON l.id = p.clientID 
    WHERE l.id = '$skID' AND p.productPage = 1";

    $res = mssql_query($select);
    $r = mssql_fetch_row($res);     

    $url = trim($r[0]); 
    $page_id = $r[1];

    return  $url .'/index.aspx?pageID='. $page_id . '&prodID=$prodId';

}
  • 写回答

3条回答 默认 最新

  • dsfsad089111 2011-11-29 14:59
    关注

    It depends, if you plan to give models some functionality like making them a little bit like active records, you can put the functionality in the class and use the class' members. Besides, do you have a good reason to use static functions? If you want to apply OOP, you have to give responsibilities to meaningful classes, a model should not both get data and do the redirection.

    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法