diff --git a/17-exercici.php b/17-exercici.php new file mode 100644 index 0000000..0814e1a --- /dev/null +++ b/17-exercici.php @@ -0,0 +1,231 @@ +name = $name; + $this->gender = $gender; + $this->age = $age; + + } + + /** + * __destruct + * + * @return void + */ + public function __destruct() + { + echo "
DESTROYED: " . $this->name . " with gender " . $this->gender . " and race " . $this->age." type: ".$this->nameType." Height ".$this->HeightType; + } + + /** + * Get the value of name + */ + public function getName() + { + return $this->name; + } + + /** + * Set the value of name + * + * @return self + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get the value of gender + */ + public function getGender() + { + return $this->gender; + } + + /** + * Set the value of gender + * + * @return self + */ + public function setGender($gender) + { + $this->gender = $gender; + + return $this; + } + + /** + * Get the value of age + */ + public function getAge() + { + return $this->age; + } + + /** + * Set the value of age + * + * @return self + */ + public function setAge($age) + { + $this->age = $age; + + return $this; + } + + + public function run(){ + return $this->name." is running"; + } + + public function throw($element){ + return $this->name." has thrown ".$element; + } + + public function getNameType(){ + return "NameType"; + } + + public function getHeightType(){ + return "HeightType"; + } + + public function __toString() + { + return "Name: ".$this->name."
Gender: ".$this->gender."
Race: ".$this->age."
"; + } + + +} + +class Heroe extends Character{ + + public string $power = 'Nothing'; + public static string $world = 'Fantasy World'; + + public function __construct(string $name,string $gender,int $age,string $nameType,string $HeightType, string $power) + { + parent::__construct($name,$gender,$age,$nameType,$HeightType); + $this->name = "Super ".$name; + + $this->power = $power; + } + + + /** + * Get the value of power + */ + public function getPower() + { + return $this->power; + } + + /** + * Set the value of power + * + * @return self + */ + public function setPower($power) + { + $this->power = $power; + + return $this; + } + + public function getName() + { + return "This method is overrride: ".$this->name; + } + + public function __toString() + { + return "Name: ".$this->name."
Gender: ".$this->gender."
Race: ".$this->age."
". "Power:".$this->power."
"; + } + + public static function powerRequest() + { + return "Power achieved"; + } + +} + +abstract class Type{ + public string $nameType; + public string $HeightType; + + public function __construct(string $nameType,string $HeightType) + { + $this->nameType = $nameType; + $this->HeightType = $HeightType; + } + + public abstract function getNameType(); + public abstract function getHeightType(); + + public function imprimir(){ + print $this->getNameType(); + } + +} + +interface Habilities +{ + public function run(); + public function throw($element); +} + +/* BASE CLASS */ +//(string $name,string $gender,int $age,string $nameType,string $HeightType) +$c = new Character("Mario","Man",35,"human","1.65"); +echo $c; + +echo $c->getName(); +echo "
"; + +/* HERENCY CLASS CHARACTER */ +//(string $name,string $gender,int $age,string $nameType,string $HeightType, string $power) +$m = new Heroe("Luigi","Man",38,"Human","1.75","Fire"); +echo $m; + +/* STATIC METHOD */ +echo Heroe::powerRequest(); +echo "
"; + +/* STATIC PROPERTY */ +echo Heroe::$world; +echo "
"; + +echo $m->getPower(); +echo "
"; + +/* OVERRIDING */ +echo $c->getName(); +echo "
"; +echo $m->getName(); + +/* ABSTRACT CLASS */ +echo "
"; +echo $c->getNameType(); +echo "
"; +echo $c->getHeightType(); + + +/* INTERFACE */ +echo "
"; +echo $m->run(); +echo "
"; +echo $m->throw("Fire"); +echo "
"; + diff --git a/OPP Basics.docx b/OPP Basics.docx new file mode 100644 index 0000000..31ddeb5 Binary files /dev/null and b/OPP Basics.docx differ diff --git a/pruebas.php b/pruebas.php new file mode 100644 index 0000000..a368df5 --- /dev/null +++ b/pruebas.php @@ -0,0 +1,28 @@ +"; + //echo print_r($funargs); + call_user_func_array([$this,'sum'],$funargs); + } + +} + +$ob = new Cal; + +try { + //$ob->sum(5,10,15); + $ob->add(10,20); +} +catch(Exception $e) { + echo 'Message: ' . $e->getMessage(); +} +/* $ob->add(10,20); */