Ciao ho capito finalmente l'erroraccio che avevo fatto...
Avevo definito gli argomenti come "private", ma siccome le dichiaravo nella classe ma le richiamavo nella sottoclasse queste non venivano viste...
Ecco il codice "finale" [ho anche imparato ad uasare i tag
]
Codice PHP:
<?php
header('Content-type: text/html;charset=utf-8');
interface role {
public function ruolo();
}
class misfits {
protected $name;
protected $power;
public function __construct ($name, $power){
$this->name = $name;
$this->power = $power;
print ("Ho appena creato un nuovo personaggio il cui nome è: $name<br>");
}
}
class hero extends misfits implements role {
public function ruolo(){
return ($this->name . " è un eroe e il suo potere è: " . $this->power . "<br><br>");
}
}
class villain extends misfits implements role {
public function ruolo(){
return ($this->name . " è un antagonista e il suo potere è: " . $this->power . "<br><br>");
}
}
?>
codice HTML:
<html> <head> <title>INTERFACCE</title> </head> <body bgcolor="#AABB00" text="#FFFFFF">
Codice PHP:
<?php
$samuel = new hero ("Samuel", "Invisibilità");print $samuel->ruolo();
$nathan = new hero ("Nathan", "Immortalità");print $samuel->ruolo();
$samuel = new villain ("Brian", "Milkchinesis");print $samuel->ruolo();
?>
codice HTML:
</body></html>