Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
目标函数won';不能在PHP中执行_Php_Eclipse_Debugging - Fatal编程技术网

目标函数won';不能在PHP中执行

目标函数won';不能在PHP中执行,php,eclipse,debugging,Php,Eclipse,Debugging,我正在使用PDT和Xdebugger(所有最新版本)以及Ubuntu 11.04上的LAMP服务器运行EclipseIndigo 调试时,对象函数(见下面的代码)不会执行;调试器只是默认设置-变量窗口完全为空,它只是冻结。页面也不会加载,它只是处于加载状态 在我开始调用对象上的函数之前,一切都很好 建议 代码如下: <?php require_once 'user.php'; require_once 'fetcher.php'; require_once 'i

我正在使用PDT和Xdebugger(所有最新版本)以及Ubuntu 11.04上的LAMP服务器运行EclipseIndigo

调试时,对象函数(见下面的代码)不会执行;调试器只是默认设置-变量窗口完全为空,它只是冻结。页面也不会加载,它只是处于加载状态

在我开始调用对象上的函数之前,一切都很好

建议

代码如下:

 <?php 
    require_once 'user.php';
    require_once 'fetcher.php';
    require_once 'inscriber.php';
    $uname=$_POST['regname'];
    $upass=$_POST['regpass'];
    $ufirst=$_POST['regfirst'];
    $ulast=$_POST['reglast'];
    $uemail=$_POST['regemail'];
    $uphone=$_POST['regphone'];

    $user = new User();
    $user->setUsername($uname); // THIS IS WHERE IT FREEZES UP
    $user->setPassword($upass);
    $user->setFirstname($ufirst);
    $user->setLastname($ulast);
    $user->setEmail($uemail);
    $user->setPhone($uphone);

    $inscriber = Inscriber::getInscriberInstance();
    $success = $inscriber->inscribeUser($user);
    ?>




<?php
class User{

    private $username;
    private $password;
    private $userID;
    private $firstname;
    private $lastname;
    private $phone;
    private $email;


    public function getUsername(){
        return $username;
    }

    public function setUsername($var){
        $this->$username = $var;
    }
    ///

    public function getPassword(){
        return $password;
    }

    public function setPassword($var){
        $this->$password = $var;
    }
    ///

    public function getUserID(){
        return $userID;
    }

    public function setUserID($var){
        $this->$userID = $var;
    }
    ///

    public function getFirstname(){
        return $firstname;
    }

    public function setFirstname($var){
        $this->$firstname = $var;
    }
    ///

    public function getLastname(){
        return $lastname;
    }

    public function setLastname($var){
        $this->$lastname = $var;
    }
    ///

    public function getPhone(){
        return $phone;
    }

    public function setPhone($var){
        $this->$phone = $var;
    }
    ///

    public function getEmail(){
        return $email;
    }

    public function setEmail($var){
        $this->$email = $var;
    }


}

这是一种“动态特性”。PHP试图用变量的内容替换
$username
。该变量不存在,因此生成的
$this->=$var
将失败

$this->username = $var;
(非静态)属性总是在没有
$
的情况下调用

在使用局部变量的getter中添加其他变量

public function getUsername(){
    return $username;
}
不知道为什么(至少尝试)在setter中使用属性,而在getter中使用局部变量

public function getUsername(){
    return $this->username;
}

旁注:“对象函数”称为“方法”

您的语法不太正确(在本例中)。您要执行以下操作:

//...

public function getUsername(){
  return $this->username; //added $this->...
}

public function setUsername($var){
  $this->username = $var; //no $-sign before 'username'
}


//...

这也适用于所有其他函数。

看不出它冻结的任何原因。您的getter是否也应该返回
return$this->someProperty
而不是
return$a_variable
??谢谢。我实际上来自Java,所以不知道是否应用了方法术语,但Java中的obv是方法。@paragoniq欢迎来到PHP的疯狂世界:-)这里有一个很好的来源,可以让您熟悉PHP中的类和对象:
//...

public function getUsername(){
  return $this->username; //added $this->...
}

public function setUsername($var){
  $this->username = $var; //no $-sign before 'username'
}


//...