CTphpnwb, on 27 December 2012 - 05:02 PM, said:
Here's how I'd do it:
Honestly, I wouldn't. It has a public attribute with a setter, uses die() instead of proper error handling, and for some reason sets a <br> tag on the attribute in the constructor. I'd suggest something more along the lines of:
<?php
class Planet {
private $world;
public function __construct() {
$this->setWorld("Hello world!");
}
public function getWorld() {
return $this->world;
}
public function setWorld($val) {
if(!empty($val)) {
$this->world = $val;
}
else {
trigger_error("Earth must contain a string", E_USER_ERROR);
}
}
}
$newPlanet = new Planet();
echo $newPlanet->getWorld() . "<br>";
$newPlanet->setWorld($_GET["Planet"]);
echo $newPlanet->getWorld() . "<br>";
Dormilich, on 27 December 2012 - 05:12 PM, said:
Good thing that hardly anyone considers JavaScript a Functional Programming Language…
It's not, really. Javascript is far more OOP than functional. Only people who can't imagine a non class based language truly OOP think of it as functional. (And only because, when denying that it's OOP, it's the easiest alternative.)

New Topic/Question
Reply





MultiQuote



|