请帮我修改此代码,以便greet函数返回预期值。
class Person {
public $name;
public function __construct($name) {
$this->name = $name;
}
public function greet($guest) {
return 'Hello $guest, my name is $name';
}
}
答案 0 :(得分:2)
我发现的问题是引号。更改single quotes to double。同样,您不能直接使用变量。与 @Override
protected void onStart() {
//GetStudentResults();
semester.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 1:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 2:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
year_of_study.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
switch (position) {
case 0:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 1:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 2:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 3:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 4:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
case 5:
inn = getIntent();
regTester = inn.getStringExtra("RegNumber");
sem = semester.getSelectedItem().toString();
yr = year_of_study.getSelectedItem().toString();
Load(regTester, sem, yr);
break;
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
//load2();
super.onStart();
}
$this->name
将打印:
class Person {
public $name;
public function __construct($name) {
$this->name = $name;
}
public function greet($guest) {
return "Hello $guest, my name is $this->name";
}
}
$p = new Person("Bob");
echo $p->greet("Alice");