這是我的PHP頁面persona.php:PHP的面向對象,函數調用
<?php
class persona {
private $name;
public function __construct($n){
$this->name=$n;
}
public function getName(){
return $this->name;
}
public function changeName($utente1,$utente2){
$temp=$utente1->name;
$utente1->name=$utente2->name;
$utente2->name=$temp;
}
}
?>
類persona
很簡單,只是表明,改變兩個用戶名如果調用構造函數和函數。
這是的index.php:
<?php
require_once "persona.php" ;
$utente1 = new persona("Marcello");
print "First user: <b>". $utente1->getName()."</b><br><br>";
$utente2 = new persona("Sofia");
print "Second user: <b>". $utente2->getName()."</b><br>";
changename($utente1,$utente2);
print " Test after name changes: first user". $utente1->getName()."</b> second user". $utente2->getName();
?>
我不明白的是如何從這裏調用changeName
功能。
所以,你知道如何調用'getName'但不能打電話'changeName()'? – zerkms
$ utente1-> changename($ utente1,$ utente2); – Ant