class showhy
{
function __construct()  //构造函数
{
$exuid=mysql_query("select *  from jdz_members where name='".$_COOKIE["jdz2009"]."'"); //显示会员时的类
$uid=mysql_fetch_array($exuid);
$this->id=$uid[uid];              //转用户ID
$this->name=$uid[name];            
$this->sex=$uid[sex];           
$this->mails=$uid[mails];          
$this->qq=$uid[qq];      
$this->lianxi=$uid[lianxi];       
$this->dizhi=$uid[dizhi];    
$this->number=$uid[number];           
$this->huifu=$uid[huifu];    
$this->xiaoxi=$uid[xiaoxi];  
$this->nxiaoxi=$uid[nxiaoxi];           
$this->dpjs=$uid[dpjs];    
$this->ldata=$uid[ldata];  
$this->data=$uid[data];  
}
}上面是PHP5的构造函数,我在本机上测试正常,没想到我传到服务器去的时候就不行了,服务器是PHP4的  。开始还以为是COOKIE的问题,经过一番调试原来是PHP 版本问题,我不知道PHP 4应该怎么写,希望有人给我改一下,这是我写的第一个类函数,不知道怎么弄成PHP4可以用的。

解决方案 »

  1.   

    在Php4中,当类中的某个函数的名称与类的名称相同时,这个函数在Php4就是构造函数。
    class showhy
    {
    function showhy()  //构造函数
    {
    $exuid=mysql_query("select *  from jdz_members where name='".$_COOKIE["jdz2009"]."'"); //显示会员时的类
    $uid=mysql_fetch_array($exuid);
    $this->id=$uid[uid];              //转用户ID
    $this->name=$uid[name];           
    $this->sex=$uid[sex];         
    $this->mails=$uid[mails];         
    $this->qq=$uid[qq];     
    $this->lianxi=$uid[lianxi];     
    $this->dizhi=$uid[dizhi];   
    $this->number=$uid[number];         
    $this->huifu=$uid[huifu];   
    $this->xiaoxi=$uid[xiaoxi]; 
    $this->nxiaoxi=$uid[nxiaoxi];         
    $this->dpjs=$uid[dpjs];   
    $this->ldata=$uid[ldata]; 
    $this->data=$uid[data]; 
    }
    }