在php中,我想在調用具有參數的函數時調用類的初始化屬性,但似乎無法弄清楚。以下是我的源代碼。PHP初始化一個類,同時調用帶參數的函數
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Task 25 NOvember 2015</title>
</head>
<body>
<?php
class Task{
\t public $name = "abc";
\t public $fname = "xyz";
\t public $dob = "10-9-90";
\t public $country = "country";
\t public $ddress = "Street";
\t public $cgpa = 3;
\t public $degree = "MCS";
\t public $year = "2014";
\t
\t public function method1($arg1, $arg2, $arg3){
\t \t $this->name = $arg1;
\t \t $this->fname = $arg2;
\t \t $this->dob = $arg3;
\t \t
\t \t return "My name is ".$this->name." ".", and my father name is ".$this->fname;
\t \t //i want to print the above values ... without giving in the function args
\t \t
\t \t
\t \t }
\t public function method2($arg4,$arg5){
\t \t
\t \t
\t \t
\t \t
\t \t }
\t public function method3(){}
\t public function method4(){}
\t public function method5(){}
\t
\t }
\t
\t
$object1 = new Task();
echo $object1->method1("","","");
?>
</body>
</html>
我是一個新的PHP程序員,我想弄清楚如何才能讓這個類的初始化屬性,隨聲附和,通過調用函數時初始化值函數的參數該類的對象。
當你做一些非常簡單的事情時,不要使用類就更容易了。這不像java,你必須使用類。在PHP中,你不必。 – frosty
感謝您的回覆,,,但是,這是我們在軟件公司的任務,,,我必須這樣做... – user3719190